h3mm3's blog

Stories from behind the keyboard

  • RSS
  • Twitter

Or, how to enable ASP.NET MVC2 to handle pseudo-file requests under IIS6

Recently I installed an ASP.NET MVC2 web application on a Windows 2003 Server, running IIS6. The Framework 4 was correctly configured, and the application ran flawlessly except when the browser requested URL’s that matched to the following route: “~/Get/{guid}.{ext}”.

Such requests are handled by the Get() method of the FileController class. The method is roughly defined like this:

public ActionResult Get(Guid guid, string ext)
   return File( ... ); 

In short, the method is meant to serve graphics and other resources to the client (via a FileStreamResult), and hides the details about the actual storage system.

The problem with IIS6 was that when it received a GET request such
it simply looked for an hypothetical (and unexisting) folder “/Get” under the web app root, and returned a HTTP error.

It turned out the problem was IIS6 trying to resolve the URL prior to pass the ASP.Net engine the request. Luckily enough, IIS6 web application configuration panel lets you define additional application maps, in order to redirect a request to the proper handler, based on the file extension of the requested file (in my case … *any* extension).

So I decided to bypass IIS6 totally and I added the .Net Framework 4.0 ISAPI filter (aspnet_isapi.dll) to the “wildcard application maps” section of the web application configuration dialog (see picture below). This setting saved my day!

Setting "aspnet_isapi.dll" as a wildcard application map

Happy programming!

No comments: