Add MIME mapping in web.config for IIS Express

asp.netConfigurationMime TypesIis Express

asp.net Problem Overview


I need to add a new MIME mapping for .woff file extensions to IIS Express.

If I add the following snippet to the "applicationhost.config" of IIS Express it works fine:

<staticContent lockAttributes="isDocFooterFileName">
    <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
    ...

But I would actually like to do add it to my "web.config" so that not every developer would need to change their "applicationhost.config" locally.

So I removed it again from the "applicationhost.config" file and added the following snippet to the project's "web.config":

<system.webServer>
  ...
  <staticContent>
    <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
  </staticContent>
</system.webServer>

Unfortunately it doesn't seem to work that way because when I try to access a .woff file I end up with a HTTP 404.3 error.

What am I doing wrong?

asp.net Solutions


Solution 1 - asp.net

Putting it in the "web.config" works fine. The problem was that I got the MIME type wrong. Instead of font/x-woff or font/x-font-woff it must be application/font-woff:

<system.webServer>
  ...
  <staticContent>
    <remove fileExtension=".woff" />
    <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
  </staticContent>
</system.webServer>

See also this answer regarding the MIME type: https://stackoverflow.com/a/5142316/135441

Update 4/10/2013

> Spec is now a recommendation and the MIME type is officially: application/font-woff

Solution 2 - asp.net

If anybody encounters this with errors like Error: cannot add duplicate collection entry of type ‘mimeMap’ with unique key attribute and/or other scripts stop working when doing this fix, it might help to remove it first like this:

<staticContent>
  <remove fileExtension=".woff" />
  <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>

At least that solved my problem

Solution 3 - asp.net

<system.webServer>
     <staticContent>
      <remove fileExtension=".woff"/>
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
    </staticContent>
  </system.webServer>

Solution 4 - asp.net

I know this is an old question, but...

I was just noticing my instance of IISExpress wasn't serving woff files, so I wen't searching (Found this) and then found:

http://www.tomasmcguinness.com/2011/07/06/adding-support-for-svg-to-iis-express/

I suppose my install has support for SVG since I haven't had issue with that. But the instructions are trivially modifiable for woff:

  • Open a console application with administrator privilages.

  • Navigation to the IIS Express directory. This lives under Program Files or Program Files (x86)

  • Run the command:

    appcmd set config /section:staticContent /+[fileExtension='woff',mimeType='application/x-woff']

Solved my problem, and I didn't have to mess with some crummy config (like I had to to add support for the PUT and DELETE verbs). Yay!

Solution 5 - asp.net

Thanks for this post. I got this worked for using mustache templates in my asp.net mvc project I used the following, and it worked for me.

<system.webServer>   
  <staticContent>
   <mimeMap fileExtension=".mustache" mimeType="text/html"/>
  </staticContent>
</system.WebServer>

Solution 6 - asp.net

I'm not using IIS Express but developing against my Local Full IIS 7.

So if anyone else get's here trying to do that, I had to add the mime type for woff via IIS Manager >> Mime Types >> Click Add link on right and then enter Extension: .woff MIME type: application/font-woff

Solution 7 - asp.net

To solve the problem, double-click the "MIME Types" configuration option while having IIS root node selected in the left panel and click "Add..." link in the Actions panel on the right. This will bring up the following dialog. Add .woff file extension and specify "application/x-font-woff" as the corresponding MIME type:

enter image description here

Follow same for woff2 with application/x-font-woff2

Solution 8 - asp.net

I was having a problem getting my ASP.NET 5.0/MVC 6 app to serve static binary file types or browse virtual directories. It looks like this is now done in Configure() at startup. See http://docs.asp.net/en/latest/fundamentals/static-files.html for a quick primer.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartin BuberlView Question on Stackoverflow
Solution 1 - asp.netMartin BuberlView Answer on Stackoverflow
Solution 2 - asp.netHawkView Answer on Stackoverflow
Solution 3 - asp.netMohamed.AbdoView Answer on Stackoverflow
Solution 4 - asp.netJayCView Answer on Stackoverflow
Solution 5 - asp.netDaman SinghView Answer on Stackoverflow
Solution 6 - asp.netNathan PratherView Answer on Stackoverflow
Solution 7 - asp.netTarun GuptaView Answer on Stackoverflow
Solution 8 - asp.netBrian WirtView Answer on Stackoverflow