Remove default HTTP modules in ASP.NET

by Mads Kristensen 23. September 2007 01:35

While hooking an HttpHandler up in web.config I thought about all the default HttpModules that are hooked up in machine.config. I did some research and found that the following modules are loaded into the ASP.NET pipeline by default:

<httpModules>
  <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
  <add name="Session" type="System.Web.SessionState.SessionStateModule" />
  <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
  <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
  <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule" />
  <add name="RoleManager" type="System.Web.Security.RoleManagerModule" />
  <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
  <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
  <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule" />
  <add name="Profile" type="System.Web.Profile.ProfileModule" />
</httpModules>

If you don't use all of them, then why not remove them from the pipeline? This is a great question that I immediately had to find the answer to, but after a while I gave up finding anything on the web. Nobody has written about it. What I really wanted to know was how this will affect the performance of the application. The logical conclusion will be that it would boost the performance to have fewer modules in the pipeline, but I want to know how much. It should also reduce the attack surface.

The next question that needs an answer is which of the modules are safe to remove. I found that the UrlAuthorization and FileAuthorization modules act as a safeguard for security reasons, so they must stay. The three authentication modules can be removed if you don’t use them or at least the ones you don’t use. The rest can safely be removed if you don’t need them.

You can remove the modules you don’t need in the web.config like so:

<httpModules>
  <remove name="PassportAuthentication" />
  <remove name="Profile" />
  <remove name="AnonymousIdentification" />
</httpModules>

If you know about the performance impact involved, please let me know.

UPDATE: Scott Guthrie says

This morning I checked my mail and saw one from Joe Kaiser. He had asked Scott Guthrie about this and here is his reply:

In general you can get some very small performance wins using this approach - although I'd probably recommend not doing it.  The reason is that some features of ASP.NET (forms auth, roles, caching, etc) will of course stop working once you remove the modules they depend on. Trying to figure out why this has happened can often be confusing.

So there you have it. Small performance gains but you might be confused later on.

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Tags: ,

ASP.NET

Comments

9/23/2007 4:14:04 AM #

Joe

Did you end up seeing exactly *what* (and how much!) the gains are?

Joe United States |

9/23/2007 4:17:41 AM #

Mads Kristensen

No, I have no idea yet. I'll try to figure it out somehow.

Mads Kristensen Denmark |

9/23/2007 11:10:37 PM #

pingback

Pingback from mhinze.com

3 Links Today (2007-09-23)

mhinze.com |

9/24/2007 11:31:37 AM #

trackback

Trackback from DotNetKicks.com

Remove default HTTP modules in ASP.NET

DotNetKicks.com |

9/24/2007 11:32:56 AM #

John S.

I'd love to see some metrics on this. Any little performance gain is worth it.

John S. United States |

9/24/2007 9:14:44 PM #

Brian

Cool find. Might it help to create a page with an overly large image and then time the page load times using FasterFox or some page load counter tool? After multiple runs with modules on and off, you may find a difference in the two... that's all I can figure at this point.

Brian United States |

9/25/2007 8:18:09 AM #

gOODiDEA

it's ok,I set my webConfig in my site before 5 month.

    <httpModules>
      <remove name="OutputCache" />
      <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" />
    </httpModules>

gOODiDEA People's Republic of China |

9/28/2007 5:53:14 PM #

pingback

Pingback from ajaxninja.com

10 Hot ASP.NET Tips and Tricks - 10/28/2007

ajaxninja.com |

Comments are closed

About the slave

Mads Kristensen Mads Kristensen
Web developer at ZYB and founder of BlogEngine.NET. More...

LinkedIn ZYB Facebook Last.fm Twitter View Mads Kristensen's profile on Technorati

The Lounge

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008