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
ASP.NET 4 introduces a new IHtmlString interface (along with a concrete implementation: HtmlString) that you can implement on types to indicate that its value is already properly encoded (or otherwise examined) for displaying as HTML, and that therefore the value should not be HTML-encoded again.
You must choose File => New => Project... instead and not File => New => Web Site... . Then select the Visual C# / Web Templates group on the left, and then choose the “ASP.NET Web Application” template in the center column. Name your project and press the OK button.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With