179

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?

hello_there_andy
  • 1,821
  • 2
  • 17
  • 48
Martin Buberl
  • 42,048
  • 25
  • 96
  • 139

8 Answers8

312

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

Community
  • 1
  • 1
Martin Buberl
  • 42,048
  • 25
  • 96
  • 139
  • 2
    Fwiw, [How to add mime types with IIS7 Web.config](http://blogs.iis.net/bills/archive/2008/03/25/how-to-add-mime-types-with-iis7-web-config.aspx) and [404 errors in IIS7 for embedded .woff font files](http://www.dirigodev.com/blog/web-development/404-errors-in-iis7-for-embedded-woff-font-files/). Voila, though a year late to the party. – ruffin Mar 12 '13 at 15:13
  • 5
    According to link, the updated mime type should now be: application/font-woff (rather than deprecated application/x-font-woff). – longda Apr 09 '13 at 23:14
  • 1
    @longda Thanks for that hint! I updated the answer to reflect that. – Martin Buberl Apr 10 '13 at 04:45
  • Does this method of defining custom MIME types in the web.config only work in IIS Express? I've tried it in a web.config deployed to IIS 6 and it does not work (throws 404). If I add the MIME type via the IIS Manager Console, it does work. – Walter Stabosz Dec 09 '13 at 20:42
  • @WalterStabosz The above works for IIS and IIS Express 7+. If you are on IIS 6 you need to configure mime-types on the server, see [configuring mime-types on IIS 6](http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/cd72c0dc-c5b8-42e4-96c2-b3c656f99ead.mspx?mfr=true). – Martin Buberl Dec 09 '13 at 20:53
  • also note the other config which at last fixed my problem in IIS http://stackoverflow.com/questions/12458444/enabling-cross-origin-resource-sharing-on-iis7 – Iman Mar 11 '15 at 06:23
61

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

Hawk
  • 1,493
  • 1
  • 14
  • 17
19
<system.webServer>
     <staticContent>
      <remove fileExtension=".woff"/>
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
    </staticContent>
  </system.webServer>
ThomasDC
  • 474
  • 3
  • 11
Mohamed.Abdo
  • 1,420
  • 16
  • 11
6

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!

JayC
  • 6,903
  • 2
  • 23
  • 40
4

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>
3

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

Nathan Prather
  • 1,968
  • 1
  • 16
  • 14
  • Thanks, this got me up to speed with getting a project running again. Things were ok with IIS7.5 with me, but I got Win8 and IIS8, and mappings in the site's web.config were being duplicated with the IIS configuration, causing errors for any static resource being requested. I removed the duplicates and things are running fine now. – rdmptn Nov 28 '13 at 14:49
3

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

Tarun Gupta
  • 5,881
  • 2
  • 36
  • 38
0

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.

Brian Wirt
  • 123
  • 7