Enabling Custom File Types in Azure Web Sites

This year I have started moving my web properties from a virtual machine to Azure Web Sites or App Services as it is called now. I will go over basics of using web sites later. Recently I ran across an issue I have previously blogged about, enabling IIS to serve the appcache file.

Recently I moved my Furniture store (my new demonstration application) to Azure Web Sites. A quick check revealed a 404 was being returned for the appCache file. After a moment I recalled the problem I solved in IIS Express a while back and figured it was something similar. Azure Web Sites is configured to enable only certain file types can be served. This limits the potential for hackers getting to configuration files and other potential security holes.

While the IIS Express solution used command line to add the mime type customizing Azure App Services requires a web.config change. In case you are not aware IIS has a default web.config. This can be modified at the web site level in the IIS Manager or in the site's web.config file. The system leverages cascading, much like CSS. This means you can override defaults, in fact when you configure things in the IIS manager it is updating the web.config file.

The section you need to modify to enable appcache is requestFiltering. Inside this element add a fileExtensions section (if you do not already have one) and then add the appcache fileExtension. When you add the extension make sure to set the allowed attribute to true.

requestFiltering is a section within the security section. The security element is part of the system.webServer section. When you have the extension added it should look something like the following.

reaquestFiltering

This works for all file types, not just appCache. For example I have encountered times where I needed to enable PDF documents. In that case I would add another add element with the fileExtension set to pdf.

For a more detailed set of instructions on how to manage the requestFiltering section refer to the online IIS documentation. It contains more details on using the IIS Manager, adding the configuration programtically as well as documentation on various properties and members.

Share This Article With Your Friends!

Googles Ads Facebook Pixel Bing Pixel LinkedIn Pixel