Why unknown file types are not served by IIS

Quick one today.

I was just trying to publish some videos that I shot with my Google Nexus One. The media format of the videos is .3gp. When I tried to watch the video on my local IIS 7.5 machine I got a detailed 404.3 error message:


I would have seen only a simple "404 - File Not Found" error if I would have made the request from a remote machine.


The Problem

IIS doesn't serve unknown file extensions. It doesn't do that because IIS handler mapping is usually done based on the extension of the request. If a handler can't be matched it falls through to the static file handler which would serve the request as text. This would be a security problem because files might be returned as text that should be executed as script (e.g. ASP, ASP.NET or PHP files) but not be returned as text. Here is a real-world example:

Let's assume you uninstalled PHP or ASP.NET but you still have some ASP.NET files or PHP files in your IIS directories.

  • Problem #1: PHP or ASP.NET files contain your code (i.e. your intellectual property). You don't want to reveal your superior coding skills to others, do you?
  • Problem #2: Often times scripts or code contains passwords, fore example to a database.

It wouldn't be a good idea for the static file handler to serve these files as text. And that's why the "don't serve unknown file extensions" feature exists.

Now let's get back to my problem. In order to serve .3gp files I simply added a Mime Type entry to the static file handler section that tells it about the file extension and it's Mime Type. Here is the command:

%windir%\system32\inetsrv\appcmd set config /section:staticContent /+"[fileExtension='.3gp',mimeType='video/3gpp']"

And while we are at it. You might run into the same problem with MP4 files. Here is the appcmd for it:

%windir%\system32\inetsrv\appcmd set config /section:staticContent /+"[fileExtension='.mp4',mimeType='video/mpeg']"

More Details

Here are some additional links in case you need more details on how to add Mime Types in IIS 6.0 or IIS 7.x.

IIS 6.0: http://support.microsoft.com/kb/326965

IIS 7.0 and 7.5: http://technet.microsoft.com/en-us/library/cc725608(WS.10).aspx

Technorati Tags: ,,,,,

No Comments