How do I register multiple paths for a HttpHandler in IIS7?
Solution 1
Daniel T's answer:
Turns out that IIS 7's handler mapping is different than IIS 6's handler mapping. In IIS 6, you can map your handlers like this in web.config
:
<configuration>
<system.web>
<httpHandlers>
<add verb="GET" path="*.jpg,*.gif,*.bmp,*.png" type="YourProject.ImageHandler" />
</httpHandlers>
</system.web>
</configuration>
It allows you to use multiple paths, comma-delimited. In IIS 7, it's in a different section:
<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>
It doesn't support multiple paths, so you need to map your handler for each path.
You'll probably have to end up mapping it in both places because Visual Studio's internal dev server uses IIS 6 (or IIS 7 running in compatibility mode), whereas the production server is probably using IIS 7.
Solution 2
You can add multiples of the same handler so long as you change the name attribute.
Daniel T.
Updated on June 14, 2022Comments
-
Daniel T. about 2 years
I have a HttpHandler that resizes images based on the querystring, so requesting something like:
will give you a resized image that's 320x240.
In the
IIS Manager
, underHandler Mappings
, I mapped my handler's path as*.jpg,*.gif,*.bmp,*.png
. However, this doesn't activate the handler. If I change it to just*.jpg
, then it works.My question is, do I have to create 4 separate mapping entries, one for each image type, or is there some way to combine multiple extensions in one path?