HttpModule not running with Visual Studio

只谈情不闲聊 提交于 2019-12-18 12:12:34

问题


I am using an HttpModule to do some URL shortening on my site. I am using Visual Studio 2008 and IIS 7, and .Net 3.5.

When the module is specified in the system.webServer element of web.config, and the site is run in IIS, it works fine. The config looks like this:

<system.webServer>
        <modules>
            <add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule" />
        </modules>...

My module attaches to the BeginRequest event, everything works. However, I can't get it to run using the built-in VS web server (Cassini). I tried moving the module config to the system.web element in web.config, no luck. I put a breakpoint on it, nothing happens.

Any thoughts on why this would be an issue?

(I also tried the Application_BeginRequest event in global.asax. Still no luck, though I'd prefer to keep everything in web.config anyway.)


回答1:


Cassini, the development web server provided with IIS uses the IIS6 module syntax, so you must duplicate the module add like so

<system.web>
  <httpModules>
    <add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule" />
  </httpModules>
</system.web>


<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <modules>
    <remove name="MinimizeModule" />
    <add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule" 
         preCondition="managedHandler" />
  </modules>
</system.webServer>

Note that I've also added a precondition to your IIS7 settings




回答2:


If you are running on IIS 7, put the module in:

<configuration>
   <system.webServer>
      <modules>
         <add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule" />
      </modules>
   </system.webServer>
</configuration>

If you are running on Cassini (Visual Studio's integrated miniature web-server), put the module in:

<configuration>
   <system.web>
      <httpModules>
          <add name="MinimizeModule" type="ClipperHouse.UrlMinimizer.MinimizeModule" />
   </system.web>
</configuration>

IIS will crash if you give it the Cassini location.
Cassini will crash if you give it the IIS location.

Whenever i deploy, i have to be sure not to deploy web.config. i also include the notes in web.config:

<system.web>
   <!--The Cassini location to add modules (comment out for IIS)-->
   <httpModules>
      <!--WARNING: IIS will crash if you leave this in here.
          IISBUG: IIS doesn't support system.web/httpModules, 
          and Cassini doesn't support system.webServer/modules
      -->
      <!--Comment out for IIS-->
      <add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
   </httpModules>
</system.web>

<system.webServer>
   <!--The IIS7 location to add modules (comment out for Cassini)
   <modules runAllManagedModulesForAllRequests="true">
      <!--IIS7 will crash if you present a system.web httpModules. -->
      <remove name="PerformanceHttpModule" />
      <add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
   </modules>
</system.webServer>

IIS's left hand doesn't know what Cassini's right hand is doing - and they both screwed it up.




回答3:


Did you try also putting the module declaration in the element? When running in dev using Cassini, that's usually the place I have to put modules to get them running.



来源:https://stackoverflow.com/questions/963545/httpmodule-not-running-with-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!