Domanda

i have a simple IHttpModule:

using System;
using System.Web;

namespace DummyPlaceholder
{
    class PerformanceHttpModule : IHttpModule
    {
        public void Init(HttpApplication application)
        {
        }

        public void Dispose()
        {
        }
    }
}

And you register HttpModules inside web.config:

<configuration>
   <system.web>
      <httpModules>
         <add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
      </httpModules>
   </system.web>
</configuration>

When i was developing, and testing locally inside my Visual Studio 2012 integrated ("Cassini") web-server, everything worked great.

When it came time to deploy to a live IIS7 web-server, the server would give a 500 Internal Server Error, and absolutely no information about the cause anywhere.

The issue is that IIS7 changed how you register HttpModules, you no longer use system.web, instead you must now use system.webServer:

<configuration>
   <system.webServer>
      <modules>
         <add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
      </modules>
   </system.webServer>
</configuration>

And now that works on IIS, but doesn't work inside Visual Studio 2012.

What i need is a solution that works in both, without having to modify the web.config file when it is being published.

The issue is that IIS7 and newer, have a new "Integrated" mode. The alternative mode is the behavior that IIS6 had, called "Classic" mode.

Obviously i need to put the Visual Studio integrated web-server into "Integrated" mode, so that it look at:

configuration/webServer/modules

for modules.

How do i do that?

Bonus Reading

È stato utile?

Soluzione

Here's a guy from the Cassini project explaining that "Integrated" modules will never be supported.

And among the dozen or so questions of people suffering with this problem, there was a hack solution:

You issue a remove to remove the system.web/httpModule, before you add the system.webServer/module module.

<configuration>
   <system.web>
      <httpModules>
         <add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
      </httpModules>
   </system.web>

   <system.webServer>
      <modules>
         <remove name="PerformanceHttpModule" />
         <add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
      </modules>
   </system.webServer>
</configuration>
  • Cassini only supports the first syntax, but doesn't understand or crash on the second
  • IIS only understand the second syntax, and crashes on the first
  • With their powers combined, you get a system as well thought out as Tomcat and WebSphere.

Altri suggerimenti

You can instruct Integrated Pipeline Mode on IIS7 to not validate the configuration (i.e., not raise an exception if there is content in the <httpModules> element). Put a <validation validateIntegratedModeConfiguration="false" /> in your <system.webServer> element.

http://www.iis.net/configreference/system.webserver/validation

<configuration>
   <system.web>
      <httpModules>
         <add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
      </httpModules>
   </system.web>

   <system.webServer>
      <modules>
         <remove name="PerformanceHttpModule" />
         <add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
      </modules>
      <validation validateIntegratedModeConfiguration="false" />
   </system.webServer>
</configuration>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top