1: // In ASP.NET 4, a new syntax <%: %> is being introduced in WebForms pages, where <%: expression %> is equivalent to
2: // <%= HttpUtility.HtmlEncode(expression) %>. The intent of this is to reduce common causes of XSS vulnerabilities
3: // in WebForms pages (WebForms views in the case of MVC). This involves the addition of an interface
4: // System.Web.IHtmlString and a static method overload System.Web.HttpUtility::HtmlEncode(object). The interface
5: // definition is roughly:
6: // public interface IHtmlString {
7: // string ToHtmlString();
8: // }
9: // And the HtmlEncode(object) logic is roughly:
10: // - If the input argument is an IHtmlString, return argument.ToHtmlString(),
11: // - Otherwise, return HtmlEncode(Convert.ToString(argument)).
12: //
13: // Unfortunately this has the effect that calling <%: Html.SomeHelper() %> in an MVC application running on .NET 4
14: // will end up encoding output that is already HTML-safe. As a result, we're changing out HTML helpers to return
15: // MvcHtmlString where appropriate. <%= Html.SomeHelper() %> will continue to work in both .NET 3.5 and .NET 4, but
16: // changing the return types to MvcHtmlString has the added benefit that <%: Html.SomeHelper() %> will also work
17: // properly in .NET 4 rather than resulting in a double-encoded output. MVC developers in .NET 4 will then be able
18: // to use the <%: %> syntax almost everywhere instead of having to remember where to use <%= %> and where to use
19: // <%: %>. This should help developers craft more secure web applications by default.
20: //
21: // To create an MvcHtmlString, use the static Create() method instead of calling the protected constructor.