Oh how I have wanted to sing about this for months, now it’s public …
Due to the popularity of the Microsoft AntiXSS Library, ASP.NET 4.5 now incorporates core encoding routines from version 4.0 of that library.
The encoding routines are implemented by the AntiXssEncoder type in the new System.Web.Security.AntiXss namespace. You can use the AntiXssEncoder type directly by calling any of the static encoding methods that are implemented in the type. However, the easiest approach for using the new anti-XSS routines is to configure an ASP.NET application to use the AntiXssEncoder by default. To do this, add the following attribute to the Web.config file:
Version=184.108.40.206, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
When the encoderType attribute is set to use the AntiXssEncoder type, all output encoding in ASP.NET automatically uses the new encoding routines.
These are the portions of the external AntiXSS library that have been incorporated into ASP.NET 4.5:
- HtmlEncode, HtmlFormUrlEncode, and HtmlAttributeEncode
- XmlAttributeEncode and XmlEncode
- UrlEncode and UrlPathEncode (new)
♫ I’ve got code in the framework, I’ve got in the framework ♫