Escape text for HTML

后端 未结 9 881
别那么骄傲
别那么骄傲 2020-11-28 04:50

How do i escape text for html use in C#? I want to do

sample=\"blah\"

and have

blah&l         


        
9条回答
  •  离开以前
    2020-11-28 05:20

    nobody has mentioned yet, in ASP.NET 4.0 there's new syntax to do this. instead of

    <%= HttpUtility.HtmlEncode(unencoded) %>
    

    you can simply do

    <%: unencoded %>
    

    read more here: 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

提交回复
热议问题