Reputation: 58
I have an MVC4 application
, and i'm trying to generate a route or ihttphandler
to process image requests, however this handler or route
is never fired.
I have the following route on the route config
:
routes.MapRoute("Images", "images/{filename}", new { controller = "Image", action = "ImageRequest" });
This way is not working for me when i use it for example to call images/demo.png
I have also tried an IhttpHandler
like shown in here without success either:
Back To Basics Dynamic Image Generation ASPNET Controllers Routing IHttpHandlers And Run All Managed Modules For All Requests.
My web config
handler section looks like this:
<!-- language: lang-xml -->
<add name="Imagehandler jpg" path="/images/*.jpg" verb="*" type="ResponsiveImages.Handlers.ImageHandler, ResponsiveImages.Handlers" />
<add name="Imagehandler jpeg" path="/images/*.jpeg" verb="*" type="ResponsiveImages.Handlers.ImageHandler, ResponsiveImages.Handlers" />
<add name="Imagehandler bmp" path="/images/*.bmp" verb="*" type="ResponsiveImages.Handlers.ImageHandler, ResponsiveImages.Handlers" />
<add name="Imagehandler png" path="/images/*.png" verb="*" type="ResponsiveImages.Handlers.ImageHandler, ResponsiveImages.Handlers" />
<add name="Imagehandler tiff" path="/images/*.tiff" verb="*" type="ResponsiveImages.Handlers.ImageHandler, ResponsiveImages.Handlers" />
If i have both the handler and the route active, the handler does not get triggered but the route does.
Can anyone tell me what i am doing wrong here?
Upvotes: 1
Views: 2662
Reputation: 20047
What order is the route in your route mappings?
MVC matches the FIRST matching route, not the most specific, I'd guess that you're hitting your default route before you images specific route.
I suspect if you're trying to hit "Images/Myfile.png" what's happening is that the route is trying to find a static file rather than using your image route.
Perhaps have a look through other questions such as this for further info:
Routing a url with extension in MVC4 won't work, tries to serve up static file
Upvotes: 3