为什么我需要停止使用<%= ...%>在Asp.net中使用<%:...%>进行渲染和开始?

Ybb*_*est 13 asp.net

我在某处读到了我应该停止使用<%= … %>渲染并开始使用<%: … %>.

谁能解释一下之间的差异<%= … %><%: … %>,什么是使用一种或另一种的优势是什么?

这是我正在阅读的幻灯片

http://ssmith-presentations.s3.amazonaws.com/ASPNET_TipsTricksTools_April2010.zip

以下是您可以从中获取更多信息的链接

http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net- MVC-2.aspx

http://haacked.com/archive/2009/11/03/html-encoding-nuggets-aspnetmvc2.aspx

Ric*_*ard 11

实际上它是<%= Server.HtmlEncode(string)%>的简短版本

看到这个链接

http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net- MVC-2.aspx

这是更好的做法,以避免Javascript攻击等.所以,如果有人添加评论到您的博客,例如,其中说iframe html或javascript,那么它将被完全呈现为类型而不是JS或iframe实际工作.