Enabling HTML files to be processed by the asp.net pipeline

Posted by on Oct 10, 2013 in Asp.net

A quick how-to here. I recently needed to process all HTML files through the ASP.Net pipeline so I could take advantage of its security features. The obvious solution to this would be to run all modules through the pipeline by adding the following to your web.config:

However, there would be a performance hit then on other static file types such as CSS, JavaScript and images. The correct way to achieve this is through the following web.config changes:

This tells the runtime that the .htm and .html extensions should be picked up and processed by the PageBuildProvider via System.Web.dll

Then, to ensure this is correctly processed by IIS or IISExpress (or any other asp.net capable web server), add the following section, also to your web.config file:

The above handlers instruct the runtime to run all requests for GET, POST, HEAD or DEBUG verbs through the PageHandlerFactory.

With this in place you can then handle HTML files through the pipeline, which is ideal for scenarios such as integrating the asp.net security architecture into static sites containing HTML files rather than a WebForms or MVC implementation.