Cyber Security & Dot Net Security

Tuesday, September 21, 2010

New Syntax for HTML Encoding Output in ASP.NET 4

New Syntax for HTML Encoding Output in ASP.NET 4

Recently Scott Guthrie has been posting a series on new features to be found in asp.net 4.0.

One feature that really caught my eye was a new way to encode your html string output as html.

Currently if you want to encode your text to html you have to do something like the following:
<div class="article">
    <%= Server.HtmlEncode("some string with an & in it") %>
</div>
But now, you can simply do this:

<div class="article">
<%: "some string with an & in it" %>
</div>

No comments: