How many times have you deployed a .NET web application to a server and found that the server was missing MIME type mappings for file types you’ve used? Answer: every time.
MIME is an internet standard created for Email exchange that extends the acceptable data that’s being transmitted beyond ASCII. Since HTTP works in a similar way to SMTP, the standard was adopted by HTTP as well to define acceptable static content types for transmission.
Under IIS, only the basic static content types are defined as acceptable by default. This is a security measure ensuring that only the content you want to allow is able to be returned. You can set MIME types definitions at both the site/application level and the server level under IIS.
With the popularity of the Bootstrap library, the .woff, .ttf, .eot, and .svg file extensions have become common requirements for many applications and websites as these files power the glyphicon halfling icon set. When you deploy your local application to a new server, you’ll likely run into an issue where your glyphicon files are resulting in a 404 error and your icons don’t render. This is because your IIS server doesn’t know about the .woff (or other) file extension and will not respond to the request.
To correct the issue, you can go into IIS and define the missing MIME types and you’ll be good to go. But what about when you deploy this application to another server, say a QA or Prod environment? You’re probably going to forget about that MIME type again. A more convenient solution is to include the mapping in your application so you no longer need to remember that step.
To include the MIME mapping with your application, you can add the sections to your Web.config file using the <mimeMap> element. You need to make sure that each mapping is distinct, so it’s wise to first remove a mapping before you add it in case it’s already defined on the server. Under IIS7+ the configuration looks like this:
Now you can deploy your application all over town without having to remember another dependency.