ASP.NET 4.0: Customizing encoding/decoding
In the previous post, I’ve said that you can customize the way request validation is performed by creating a RequestValidator derived class. ASP.NET 4.0 will also let you run your custom logic for encoding: to do that, you need to create a new HttpEncoder derived class and override the methods you want to customize.
If you look at the HttpEncoder’s members list, you’ll see that it introduces several virtual methods which you can override to perform different actions. For instance, the HtmlEncode method is used whenever you call the Server.HtmlEncode method in your page.
After creating your custom encoder, you need to make ASP.NET use it by setting the encoder type in the httpRuntime section. The easiest way to achieve that is by adding something like this to the web.config file:
And that’s it for now. Stay tuned for more on ASP.NET 4.0.