如何注册一个适用于VS2012 Cassini和IIS7的HttpModule?
我有一个简单IHttpModule
:如何注册一个适用于VS2012 Cassini和IIS7的HttpModule?
using System;
using System.Web;
namespace DummyPlaceholder
{
class PerformanceHttpModule : IHttpModule
{
public void Init(HttpApplication application)
{
}
public void Dispose()
{
}
}
}
你注册的HttpModules内web.config
:
<configuration>
<system.web>
<httpModules>
<add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
</httpModules>
</system.web>
</configuration>
当我发展,我的Visual Studio 2012中进行本地测试集成( “卡西尼” 号)网络服务器,一切都很好。
当是时候部署到现场IIS7 Web服务器,该服务器将give a 500 Internal Server Error, and absolutely no information about the cause anywhere.
的问题是,IIS7改变了你注册的HttpModules,你不再使用system.web
,而不是你现在必须使用system.webServer
:
<configuration>
<system.webServer>
<modules>
<add name="PerformanceHttpModule" type="DummyPlaceholder.PerformanceHttpModule"/>
</modules>
</system.webServer>
</configuration>
而现在,在IIS上工作,但在Visual Studio中不起作用2012
我需要的是一个解决方案可以在两者中使用,而不必在发布文件时修改web.config
文件。
问题是,IIS7和更新,有一个新的“集成”模式。替代模式是IIS6的行为,称为“经典”模式。
很显然,我需要把Visual Studio集成的Web服务器为“集成”模式,使之看:
configuration/webServer/modules
的模块。
我该怎么做?
奖金阅读
下面是来自卡西尼项目解释"Integrated" modules will never be supported的人。
和人民这个问题遭受十几问题中,有一个黑客的解决方案:
您发出remove
删除system.web/httpModule
,在添加之前system.webServer/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>
- 卡西尼仅支持第一语法,但在第二
- 不理解或崩溃IIS只知道第二语法,并在第一
- 凭借他们的力量结合起来,你崩溃像Tomcat和WebSphere一样获得一个系统。
您可以指示IIS7上的集成管道模式不验证配置(即,如果<httpModules>
元素中有内容,则不会引发异常)。将<validation validateIntegratedModeConfiguration="false" />
放入您的<system.webServer>
元素中。
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>