0

I want to create a custom image URL handler, which can handle GET requests with the following URL pattern:

http://blah.com/images/image1.gif

To handle this I created the following route:

        routes.MapRoute(
            name: "appImages",
            url: "images/{*imageName}",
            defaults: new { controller = "Image", action = "Grab" });

This does not seem to work even for images with no spaces in their names. What am I doing wrong?

jujiro
  • 190
  • 1
  • 1
  • 11
  • 1
    Ensure you don't have a folder titled images as IIS(I believe) will look for logical (it exists) folders/files first, then gives it to the .NET pipeline for further processing if none are found. If you have an images folder, the request never makes it to the route engine. – Tommy Oct 26 '15 at 01:22
  • 1
    That was it. I had a physical images folder matching the uri. Thanks Tommy. – jujiro Oct 26 '15 at 10:23
  • Awesome - glad you got it working! I posted this as an answer if anyone else stumbles upon this question. – Tommy Oct 26 '15 at 10:46

1 Answers1

0

By default, IIS looks for existing files and folders when it processes the request from the user. If you have an existing folder or file, then IIS will simply try and retrieve the file from disk rather than passing the request on to the .NET pipeline / routing engine.

Check to see if you have a folder already called images in your solution. If you do have this folder, I suggest (the easiest method) either changing your controller name or the existing folder name in order to resolve your issues.

Tommy
  • 39,592
  • 10
  • 90
  • 121