IIS7 里注册HttpModule和IIS6 里注册时候 在WEB.CONFIG里有所不同

时间:2022-06-01 22:15:59

The only weird part here is getting a handle to the logger. I’m using an IoC container in my application, however I can’t tell IIS how to build up my RequestDurationLoggerModule, so I’m stuck using the Service Locator pattern. The container could be a singleton, but I don’t like singletons, so I implemented IServiceProvider in Global.asax instead. All that’s left now is wiring in the module. Since Cassini behaves like IIS6, you have to use the legacy style configuration, which looks like this:

  <system.web>
    <httpModules>
      <addname="..."type="MyApplication.RequestDurationLoggerModule, MyApplication"/>
    </httpModules>
  </system.web>
 

For IIS7 though, you add it like this:

  <system.webServer>
    <modules>
      <addname="..."type="MyApplication.RequestDurationLoggerModule, MyApplication"/>
    </modules>
  </system.webServer>