webconfig中注册HttpHandler报错:检测到在集成的托管管道模式下不适用的 ASP.NET 设置。

Posted 追云逐日

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webconfig中注册HttpHandler报错:检测到在集成的托管管道模式下不适用的 ASP.NET 设置。相关的知识,希望对你有一定的参考价值。

为什么会出现以上错误?

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

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

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

有两种解决方式:

  第一种方法、配置应用程序池

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

 

第二种:修改配置文件webconfig

修改前:

<configuration>
    <system.web>
      <httpHandlers>
        <add path="*.aspx" verb="*" type="CustomerHander, ClassLibrary1" />
      </httpHandlers>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>
</configuration>

 

修改后:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <handlers>
      <add name="CustomerHander" path="*.aspx" verb="*" type="CustomerHander, ClassLibrary1" preCondition="integratedMode" />
    </handlers>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
</configuration>

如图项目结构如下:

1.自定义hander是引用的其他类库,所以type属性用逗号分割,前面是:全限定类名 后面是:所在的dll文件(不包括后缀名)

 

2.如果hander在本项目中,如图:

则web.config文件中的配置如下:

type属性只填写类名就可以了。

 

补充:如果想保留原先设置,更改后可以设置禁止验证集成模式(validateIntegrateModeConfiguration="false"),是不会产生错误的。如图

以上是关于webconfig中注册HttpHandler报错:检测到在集成的托管管道模式下不适用的 ASP.NET 设置。的主要内容,如果未能解决你的问题,请参考以下文章

注册URL模式与HttpHandler的映射关系

IHttpModule在webconfig中的注册

httphandler httpmodule一些个人理解

ASP.NET路由系统实现原理:HttpHandler的动态映射

WebConfig authentication mode="Forms"错误问题

#.NET EF中HttpModule与HttpHandler对象的基本使用