为何会出现以上错误?web
在IIS7的应用程序池有两种模式,一种是“集成模式”,一种是“经典模式”。spa
经典模式 则是咱们之前习惯的IIS 6 的方式。debug
若是使用集成模式,那么对自定义的httpModules 和 httpHandlers 就要修改配置文件,须要将他们转移到<modules>和<hanlders>节里去。3d
有两种解决方式:code
第一种方法、配置应用程序池blog
在IIS7上配置应用程序池,而且将程序池的模式改成“经典”,以后一切正常。如图:get
第二种:修改配置文件webconfigit
修改前:io
<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>
修改后:class
<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"),是不会产生错误的。如图