ASP.NET Remove httpModules

Performance optimization

You want to remove HTTP modules from your ASP.NET application's pipeline. Microsoft's documentation states that you can save memory and CPU cycles by removing httpModules. Here we look at how you can remove httpModules from your site and what this helps with.

This ASP.NET article shows how to remove HTTP modules with Web.config.

Remove httpModules

First, many HTTP Modules are not necessary for most sites. Many ASP.NET applications do not use AJAX, probably the large majority. ScriptModule, which is included by default in ASP.NET web sites, is for AJAX. To remove it, open Web.config and scroll down to where you see the following section, and delete it.

Web.config fragment [XML]

<httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule ...
</httpModules>

Next steps. Next, add these entries to the httpModules section using simple XML comments. Additionally, you can comment out <httpHandlers>, as well as the section at the bottom called <system.webServer>.

Web.config fragment [XML]

<httpModules>
    <remove name="OutputCache"/>
    <remove name="Session"/>
    <remove name="WindowsAuthentication"/>
    <remove name="FormsAuthentication"/>
    <remove name="PassportAuthentication"/>
    <remove name="RoleManager"/>
    <remove name="UrlAuthorization"/>
    <remove name="FileAuthorization"/>
    <remove name="AnonymousIdentification"/>
    <remove name="Profile"/>
    <remove name="ErrorHandlerModule"/>
    <remove name="ServiceModel"/>
</httpModules>

Testing your site. Now, run your project in Visual Studio's debugger and the ASP.NET development web server. If you are not using any of the required modules, your site will be slightly faster. Very few ASP.NET sites use all of these modules, so most sites can probably benefit from this optimization.

Research

This section provides information

The document at Microsoft is called "Performance Tips and Tricks in .NET Applications." Halfway through, it offers some useful tips regarding ASP.NET.

MSDN reference

Remove Unnecessary HTTP Modules. "Depending on the features used, remove unused or unnecessary http modules from the pipeline. Reclaiming the added memory and wasted cycles can provide you with a small speed boost." The document specifically notes that this is not a big gain.

Performance

I don't have benchmarks for this optimization. However, when Microsoft states something in a public document, they usually do have numbers they track internally. As Scott Guthrie has stated, the ASP.NET developers keep very precise performance metrics through the development. I verified in the Visual Studio debugger that the string[] array containing the HttpModule list was reduced to 1 from its original number, which was greater than 10.

Summary

ASP.NET web programming framework

We looked at how you can modify the Web.config in your ASP.NET application to remove the httpModules and probably enhance performance. When performance tuning your application, you can simply add <remove> elements to Web.config to reduce memory and improve speed.

ASP.NET Tutorials
.NET