HttpModule not running with Visual Studio
Asked Answered
V

3

21

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.)

Valorous answered 8/6, 2009 at 5:41 Comment(0)
B
41

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

Burtburta answered 8/6, 2009 at 9:1 Comment(3)
tried this. My module .ctors and Init()s but any attempt to attach event handlers is met with PlatformNotSupportedException - Cassini seems to totally ignore the IIS7 section.Sukkoth
Well yes, Cassini does - you have to add the IIS6 syntax too, hence having both thereBurtburta
Thanks for this - I had the problem the other way round and was going slightly crazy. I would count this as an IIS bug myself: either it is registered (in which case I shouldn't need to register it again) or it isn't registered (in which case I shouldn't need to remove it before registering it again!). But that's another issue. Main thing is it works now. ThanksMoncada
E
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.

Encasement answered 9/1, 2015 at 16:20 Comment(0)
K
0

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.

Kenlay answered 8/6, 2009 at 8:41 Comment(1)
Could you expand on this further? I'm not sure what you mean.Medicament

© 2022 - 2024 — McMap. All rights reserved.