February 2010
Beginner
400 pages
11h 13m
English
All web developers should be aware that it is important to HTML-encode values that are output to prevent XSS attacks (particularly if you have received them from the user). ASP.NET 4.0 offers a new markup syntax that uses the colon character to tell ASP.NET to HTML-encode the expression:
<%: "<script>alert('I won\'t be run');</script>" %>
When ASP.NET parses this, it does the following:
<%= HttpUtility.HtmlEncode(YourVariableHere) %>
It is important to bear in mind that using this syntax may not negate all XSS attacks if you have complex nested HTML or JavaScript.
ASP.NET 4.0 includes the new HtmlString class that indicates an expression is already properly encoded and should not be reexamined. This ...