2013-10-03 55 views
2

我有一個簡單IHttpModule如何註冊一個適用於VS2012 Cassini和IIS7的HttpModule?

using System; 
using System.Web; 

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

     public void Dispose() 
     { 
     } 
    } 
} 

你註冊的HttpModulesweb.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 

的模塊。

我該怎麼做?

獎金閱讀

回答

1

下面是來自卡西尼項目解釋"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一樣獲得一個系統。
1

您可以指示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>