Hi,
Scott Hanselman's latest blog entry about the new VS 2010 features mentions "the new <%: %> encoding syntax". What does it do? Searching for these tags with google doesn't seem to be possible...
Thanks,
Adrian
Hi,
Scott Hanselman's latest blog entry about the new VS 2010 features mentions "the new <%: %> encoding syntax". What does it do? Searching for these tags with google doesn't seem to be possible...
Thanks,
Adrian
I think it ensures that the text contained inside is sanitized, so that java script can't be injected into the page
so if you have
userdata = alert ("textstring")
<%= userdata %>
will show a messagebox in on the page
<%: userdata %>
will show the text 'alert ("textstring")'
It will automatically HTML-encode the enclosed expression.
So...
<%: yourString %>
... is equivalent to ...
<%= HttpUtility.HtmlEncode(yourString) %>
See the following MSDN link for more info:
It outputs HTML with the entities encoded. It's short-hand for
<%= HttpUtility.HtmlEncode("Some string") %>
Furthermore, it can be extended to do extra cool stuff, like protecting the output against XSS, as Phil Haack demonstrated.
Phil Haack, Scott Guthrie and Scott Hanselman have blogged extensively about new and improved features in .NET 4.
Actually this Google search lead me to this explanation of Scott Guthrie.
Its purpose is to help prevent against XSS attacks via encoding the HTML.