Saturday, June 9, 2012

Adding httpModule Handlers in web.config Not Working in IIS 7

There are several tutorials on how to use HTTP modules to extend ASP.NET processing. If you google httpModules, the first several entries point to the Microsoft websites that teach you how to create and configure them. I used this one in particular.

Extending ASP.NET Processing with HTTP Modules

If you follow all the instructions and copy and paste their code, it may not work for you if you are using IIS 7. The problem is that the tutorial was not updated for later versions of IIS (as of the posting of this blog article) and IIS 7 changed the configuration for custom HTTP modules within web.config. The tutorial tells you to add the following in your web.config:

<configuration>
  <system.web>
    <httpModules>
      <add name="RequestTimeIntervalModule" type="Samples.Aspnet.HttpModuleExamples.RequestTimeIntervalModule">
      </add>
    </httpModules>
  </system.web>
</configuration>


Which is how it is in previous versions of IIS. But IIS 7 looks for it here.

<configuration>
  <system.webServer>
    <modules>
      <add name="RequestTimeIntervalModule" type="Samples.Aspnet.HttpModuleExamples.RequestTimeIntervalModule">
      </add>
    </modules>
  </system.webServer>
</configuration>

Note that it is possible to put both sections in your web.config in case you want to run your web application in both versions of IIS. Also, the project migration tool within VS 2008 does not automatically add the corresponding entries in system.webServer even if you have  httpModules defined in your web.config, so this is something you have to add manually when you're upgrading IIS to version 7.

1 comment:

  1. Thanks for the post. I had been looking for something related and found your web site in the process.. I will definitely be back for more.

    ReplyDelete