我有一个 HttpHandler 可以根据查询字符串调整图像大小,因此请求如下:
会给你一个 320x240 的调整大小的图像。
在
IIS Manager
, 下 Handler Mappings
,我将处理程序的路径映射为 *.jpg,*.gif,*.bmp,*.png
.但是,这不会激活处理程序。如果我将其更改为 *.jpg
,那么它就起作用了。我的问题是,我是否必须创建 4 个单独的映射条目,每个图像类型一个,或者是否有某种方法可以在一个路径中组合多个扩展?
最佳答案
丹尼尔 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。
关于asp.net - 如何在 IIS7 中为 HttpHandler 注册多个路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3050500/