Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the new <%: %> encoding syntax in Visual Studio 2010 do?

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

like image 700
Adrian Grigore Avatar asked Apr 16 '10 08:04

Adrian Grigore


People also ask

What is the syntax for HTML encode introduced in asp net 4 version?

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.

How do I open a Web form in Visual Studio 2010?

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.


1 Answers

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.

like image 142
alastairs Avatar answered Sep 21 '22 12:09

alastairs