我有一个基于查询字符串调整图像大小的HttpHandler,所以请求类似的东西:
将为您提供320x240的重新调整大小的图像。
在IIS Manager
下Handler Mappings
下,我将处理程序的路径映射为*.jpg,*.gif,*.bmp,*.png
。但是,这不会激活处理程序。如果我将其更改为*.jpg
,则可以正常工作。
我的问题是,我是否必须创建4个单独的映射条目,每个映像类型一个,或者是否有某种方法可以在一个路径中组合多个扩展名?
答案 0 :(得分:17)
Daniel T的回答:
原来,IIS 7的处理程序映射与IIS 6的处理程序映射不同。在IIS 6中,您可以在web.config
:
<configuration>
<system.web>
<httpHandlers>
<add verb="GET" path="*.jpg,*.gif,*.bmp,*.png" type="YourProject.ImageHandler" />
</httpHandlers>
</system.web>
</configuration>
它允许您使用逗号分隔的多个路径。在IIS 7中,它位于不同的部分:
<configuration>
<system.webServer>
<handlers>
<add name="ImageHandler for JPG" path="*.jpg" verb="GET" type="YourProject.ImageHandler" resourceType="File" />
<add name="ImageHandler for GIF" path="*.gif" verb="GET" type="YourProject.ImageHandler" resourceType="File" />
<add name="ImageHandler for BMP" path="*.bmp" verb="GET" type="YourProject.ImageHandler" resourceType="File" />
<add name="ImageHandler for PNG" path="*.png" verb="GET" type="YourProject.ImageHandler" resourceType="File" />
</handlers>
</system.webServer>
</configuration>
它不支持多个路径,因此您需要为每个路径映射处理程序。
您可能不得不最终在两个地方映射它,因为Visual Studio的内部开发服务器使用IIS 6(或在兼容模式下运行的IIS 7),而生产服务器可能使用IIS 7.
答案 1 :(得分:6)
只要更改名称属性,就可以添加同一处理程序的多个部分。