Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a HttpHandler that resizes images based on the querystring, so requesting something like:

http://server/image.jpg?width=320&height=240

will give you a resized image that's 320x240.

In the IIS Manager, under Handler 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?

like image 650
Daniel T. Avatar asked Jun 16 '10 03:06

Daniel T.


People also ask

Which of the following elements registers the custom handler?

The configuration element registers the custom handler factory by class name and maps the . sample file name extension to that handler. Because you are registering a custom file name extension, you register the handler in both the handlers section and the httpHandlers section.

Where are IIS handler mappings stored?

This file is located in %windir%\Microsoft.NET\Framework\framework_version\CONFIG. ApplicationHost. config. This file is located in %windir%\system32\inetsrv\config.


1 Answers

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.

like image 136
Oleg Grishko Avatar answered Sep 21 '22 14:09

Oleg Grishko