检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法

我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误:

HTTP 错误 500.23 - Internal Server Error

检测到在集成的托管管道模式下不适用的 ASP.NET 设置。

为什么会出现以上错误?

在IIS7的应用程序池有两种模式,一种是“集成模式”,一种是“经典模式”。

经典模式 则是我们以前习惯的IIS 6 的方式。

如果使用集成模式,那么对自定义的httpModules 和 httpHandlers 就要修改配置文件,需要将他们转移到<modules>和<hanlders>节里去。

两种解决方法:

在IIS7上配置应用程序池,并且将程序池的模式改为“经典”,之后一切正常。

但这样只是权宜之计,用了IIS7.x,但实际只发挥了6的功能,另外,在一些ASP.NET MVC程序中的效果也不好,所以,我们尝试以下解决方法:

第二种方法、修改web.config配置文件:

例如原先设置(你的环境中可能没有httpModules,httpHandlers节点)

<system.web>

    ............

    <httpModules>
        <add name="MyModule" type="MyApp.MyModule" />
    </httpModules>
    <httpHandlers>
      <add path="*.myh" verb="GET" type="MyApp.MyHandler" />
    </httpHandlers>


</system.web>

在IIS7应用程序池为“集成模式”时,改为:

<system.web>

    ...........

</system.web>

<system.webServer>

    <modules>
      <add name="MyModule" type="MyApp.MyModule" />      
    </modules>
    <handlers>
      <add name="MyHandler" path="*.myh" verb="GET" type="MyApp.MyHandler" preCondition="integratedMode" />
    </handlers>

</system.webServer>

如果你的web.config没有httpModules,httpHandlers节点,则直接在节点system.webServer中添加:

<validation validateIntegratedModeConfiguration="false" />  

禁止验证集成模式,来避免错误。