MVC ASPX(webForm)视图引擎 lt;%:%gt; 与lt;%=%gt;的差别

控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication2.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            ViewData["Script"] = "<script>alert('Dome')</script>";
            return View();
        }

    }
}

视图

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        <!-- 假设用=号的话,就是原封不动的输出ViewData["Script"]中的代码,这样easy遭到跨站脚本的攻击,不够安全,所以这里是弹出一个对话框吗,对话框内容为Dome-->
        <%=ViewData["Script"] %>  

         <!--<%: %>相当于<%=Html.Encode(<script>alert('Dome')</script>) %> 推荐大家用冒号,这里输出的是<script>alert('Dome')</script>-->  
        <%:ViewData["Script"] %> 

        <!--假如说我如今就是想在前台页面输出一些Html标签,或一些代码,就想让它原封不动的去运行那段代码,比方说我如今就想给一个Div标签放到页面去,怎么辦呢,下面三种方法都能够,并且不用=号更安全-->

        <%:Html.Raw("<div>我是div标签</div>") %>

        <%:new HtmlString("<p>我是p标签</p>") %>

        <%:new MvcHtmlString("<p>我也是p标签</p>") %>

       

    </div>
</body>
</html>



Database error: [Table 'ac_search_cache' is marked as crashed and should be repaired]

SELECT * FROM ac_search_cache WHERE hash = '8c09fda1067fbf9c4314235e8d8be94b250a9c5d' LIMIT 1;