1

I have a ASP.Net MVC 4.5 WebAPI controller (IIS8) that can serve static images files from a repository. The URLs I want to use are like;

 http://example.com/blob/image/123412341324.jpg

The trouble is '.jpg' here appears to be going through the static file handler, which for the most part is what I want to keep. I don't want all static files to go through ASP.Net just the ones on this URL path.

Is there any way I can configure ASP.Net to serve up these files without runAllManagedModulesForAllRequests and without modifying the url such as removing the file extension? Ideally, an IIS routing mechanism that looked at the folder path /blob/image/;

 http://example.com/blob/image/123412341324.jpg -- route through ASP.Net WebAPI

 http://example.com/staticimages/123412341324.jpg    -- do not route through ASP.Net
 http://example.com/anywherelese/123412341324.jpg    -- do not route through ASP.Net

I know I could write a separate 'IHttpHandler' but I'd like to route it through the MVC WebAPI controller if possible.

cirrus
  • 5,624
  • 8
  • 44
  • 62

1 Answers1

1

So it turns out this is quite easy to do with handler mappings. I tried a few wildcards but although *.jpeg works blob/image/*.jpeg does not. Eventually, with a little help from this post I came up with the following entry in my app's web.config which does what I need and routes all requests for this controller;

<system.webServer>
    <handlers>
...
        <add name="my-blob-jpeg-ExtensionlessUrlHandler-Integrated-4.0" path="blob/image" verb="GET,HEAD,POST,DEBUG,DELETE,PUT,PATCH" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
...
    </handlers>
</system.webServer>

It's not specific to image files but I don't plan on putting any other static content along that path so I'm good.

Community
  • 1
  • 1
cirrus
  • 5,624
  • 8
  • 44
  • 62