How do I register multiple paths for a HttpHandler in IIS7? How do I register multiple paths for a HttpHandler in IIS7? asp.net asp.net

How do I register multiple paths for a HttpHandler in IIS7?


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.


You can add multiples of the same handler so long as you change the name attribute.