asp.net Web.config 在不同版本的IIS配置的IHttpHandler的访问路径,以及经典模式和集成模式不同的配置

时间:2022-06-26 07:04:24

如果IIS7.0使用.net4.0以上版本的框架,<system.web>中的httpHandlers节点就没有用了,而应该使用微软专为.net4.0以上版本设计的新节点<system.webServer>来配置ashx的handlers(IHttpHandler)

handlers(IHttpHandler)在IIS7.0 .net4.0部署站点的时候使用 经典模式 应该在<system.web>节点下配置:

   <system.web>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="GiftImgUpload.aspx" type="Web.Ajax_Handle.GiftImageUploadHandler, Yunsoft.Web"/>
<add verb="*" path="EditPhotoHandle.aspx" type="Web.Ajax_Handle.EditPhotoHandle, Yunsoft.Web"/>
</httpHandlers>
</system.web>

handlers(IHttpHandler)在IIS7.0 .net4.0部署站点的时候使用 集成模式 应该在<system.webServer>节点下配置:

  <system.webServer>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="GiftImgUpload" verb="*" path="GiftImgUpload.aspx" type="Web.Ajax_Handle.GiftImageUploadHandler, Yunsoft.Web"/>
<add name="MapHandle" verb="*" path="MapHandle.aspx" type="Web.AjaxHandle.MapHandle"/>
<add name="MapMarkImgHandle" verb="*" path="MapMarkImgHandle.aspx" type="Web.AjaxHandle.MapMarkImgHandle"/>
<add name="PageHandlerFactory" verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
</handlers>
</system.webServer>

修改站点托管管道模式:

asp.net Web.config 在不同版本的IIS配置的IHttpHandler的访问路径,以及经典模式和集成模式不同的配置

说明一下:

verb可以是“POST”或 “GET”,表示对GET或POST的请求进行处理。“*”表示对所有的请求进行处理。

path指明相对应的文件进行处理,"*.aspx" 表示对发给所有的ASPX页面的请求进行处理,也可以指明路径,
如,“/test/*.aspx” 表明只对test目录下的aspx文件进行处理。

type属性中,指明要进行处理的类名,但是这个类一定要继承IHttpHandler这个接口。