I have an MVC2 application, and HttpHandler Library. The library, to simplify, serves an image. The problem is that if I invoke this handler from the root page ( http://whatever/ ), everything works fine. If, however, I change the Global.asax, so the same page now has the address of http://whatever/controller/action – it doesn’t work (ALT text comes out instead of image).
I didn’t write the handler library, but I have the code; so I put a breakpoint in ProcessRequest function of IHttpHandler implementation. For good situation the breakpoint gets triggered, but for bad case it isn’t. So, I assume that the handler isn’t invoked for non-root pages.
This is what I have in system.webServer/handlers section:
<add name="ImageHandler" verb="*"
path="ImageLib.axd" type="ImageHandler, ImageHandler" />
The view page has
<img src="ImageLib.axd?image=img001.jpg" alt="real image here" />
I don’t know if MVC plays any role in it… the old WebForms application works fine with the same settings.
Hopefully, I provided all that I know. Of course, if something isn’t clear, I’ll be happy to explain as much as I can!
Try this:
The fundamental problem is that you are relatively referencing ImageLib.axd. A browser will try to access it from wherever it is…in your case, when it requests the image, it is requesting it from http://whatever/controller/action/ImageLib.axd. I am assuming you need it to request from http://whatever/ImageLib.axd.
Note that simply adding the preceeding whack (/) is not necessarily going to solve your problem. If ImageLib.axd is in some sub folder off of your root, you would have to include that. If your ImageLib.axd handler is in a folder called handlers off of your web site root, you would do the following: