20

I have a custom HTTP module for an ASP.NET MVC3 website that I'm loading from web.config:

<system.web>
    <httpModules>
      <add name="MyModule" type="MySolution.Web.MyHttpModule, MySolution.Web" />
    </httpModules>
</system.web>

The module is loaded correctly when I run the site from within the VS web server (the break point in my Init method is hit) but when I host it in IIS it seems to be ignored (the breakpoint is missed and the module's functionality is absent from the site). I have tried it on two separate IIS boxes with a similar result.

What am I doing wrong? Is there a setting I have to flick in enable IIS to load modules from a site's web.config?

Mike Chamberlain
  • 595
  • 1
  • 4
  • 12

3 Answers3

26

I figured this out shortly after I asked the question - IIS7 uses a different schema for the web.config. The correct place to load a module is now:

<system.webServer>
  <modules>
    <add name="MyModule" type="MySolution.Web.MyHttpModule, MySolution.Web" />
  </modules>
</system.webServer>
Mike Chamberlain
  • 595
  • 1
  • 4
  • 12
  • 3
    've run into this same issue and this post help me fix it. I did find that it is required to keep both system.web/httpModules and system.webServer/modules to have my custom module work on both the local dev server and the production server. – Ido Ran Aug 16 '12 at 05:49
  • WOW! thank you. I was really banging my head against the wall on this one. – Alex C Oct 07 '15 at 15:45
  • 4
    Probably the difference is not IIS6 vs IIS7 but classic vs integrated mode. – Jan Zahradník Mar 23 '16 at 20:58
3

7 years later: It is not specific to the IIS version, it is specific to the application pool mode: classic versus integrated.

  <system.webServer><!--for integrated mode-->
    <modules>
      <add name="modulename" type="blabla.modulenamehere" />
    </modules>
  </system.webServer>

  <system.web><!--for classic mode-->
     <httpModules>
      <add name="modulename" type="blabla.modulenamehere" />
    </httpModules>
  </system.web>
TamerDev
  • 31
  • 1
1

I have a similar problem. My Solution involved removing the Module first and then re-adding it to the system.webServer namespace.

<system.webServer>
   <modules>
     <remove name="MyModule"/>
     <add name="MyModule" type="MySolution.Web.MyHttpModule, MySolution.Web" />
   </modules>
</system.webServer>

This may be because we deploy to two different IIS servers. one on server 2003 (iis 6) and one on server 2008 (iis7+). So adding the module to seemed to block it from loading in the namespace. I could be wrong here...

Dai Bok
  • 143
  • 7