Azure MIME mapping

It turns out that Azure Websites have some MIME mapping problems that a default IIS installation has not.

I’ve been playing around with serving files through mvc. Basically, what I did was:

public ActionResult GetFile(string path)
            if (string.IsNullOrEmpty(path))
                return HttpNotFound();

            var fileName = MapFilePath(path);
            return File(fileName, System.Web.MimeMapping.GetMimeMapping(fileName)); 

This works fine on my local machine (using IIS Express). Surprisingly, after publishing to Azure Website, I received a download alert instead of file content inside the browser. After some quick debugging, I found out that the file extension (.xhtml in this case) was being mapped to application/octet-stream instead of application/xhtml+xml. Interestingly, GetMimeMapping uses IIS MIME mapping: So, my local IIS has this extension mapped and Azure has not. This may be a cool feature, but in this case it just gets in my way. So, instead of adding mappings to my web.config, I decided to hardcode the mapping dictionary, using this little class: This gist is similar, but it does not containt xhtml:

Now, that’s better.