28

I was adding the ability to serve SVG & WOFF files to my Azure hosted web application. I found the following instructions:

https://blogs.iis.net/richma/archive/2014/01/07/adding-mime-types-to-your-windows-azure-web-site.aspx

Which I have followed by adding the below text to my Web.config file:

<staticContent>
    <mimeMap fileExtension=".json" mimeType="application/json" />
    <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
</staticContent>

This works when published to Azure. However, now I get the following error from IIS-Express whenever I attempt to start up the website in Debug mode locally for every resource the website attempts to serve.

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:

  • Module: CustomErrorModule
  • Notification SendResponse
  • Handler StaticFile
  • Error Code 0x800700b7
  • Config Error Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute 'fileExtension' set to '.svg'
  • Config File snip\web.config
  • Requested URL http://snip:14466/resources/img/snip.png
  • Physical Path C:*snip*\Resources\img*snip*.png
  • Logon Method Anonymous
  • Logon User Anonymous

Config Source:

   58: <mimeMap fileExtension=".json" mimeType="application/json" />
   59: <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
   60: <mimeMap fileExtension=".woff" mimeType="application/x-font-woff"/>

It clearly hates my mimeMap for .svg but this works fine out in Azure Websites. Is there something I am missing for locally running these changes to the Web.config?

Community
  • 1
  • 1
Jesse VanDerPol
  • 953
  • 1
  • 7
  • 15
  • Of course I find [this answer](http://stackoverflow.com/questions/16201406/adding-mimemap-entry-causes-500-for-other-static-content-on-iis-express?rq=1) after already posting my question: Fixes the issue for me. – Jesse VanDerPol Apr 28 '14 at 21:01
  • can you post your answer here or delete this question if it's really a duplicate – mmohab Apr 28 '14 at 21:11
  • @mmohab I will post an answer as soon as my 8-hr wait window is up. I would like to keep the question up and answer it. If this isn't a terrible practice. I looked really hard for an answer before posting the question. I think having another question out there may help people find a solution quicker in the future. What is your opinion on this? – Jesse VanDerPol Apr 28 '14 at 21:16
  • if your question is identical to other question then probably you should remove it. Otherwise if your question is slightly different then you can keep it. if you decide to keep it it's nice to provide and answer to it. – mmohab Apr 28 '14 at 21:26

2 Answers2

57

And of course I find this answer after already posting my question:

Adding <mimeMap> entry Causes 500 for Other Static Content on IIS Express

So the issue is that my local IIS configuration has the modules already loaded, meanwhile the production environment doesn't. So to fix the issue for both environments you need to make sure the mimeMaps are unloaded before loading them.

The code is the following for the fix:

<staticContent>
    <remove fileExtension=".json"/>
    <mimeMap fileExtension=".json" mimeType="application/json" />
    <remove fileExtension=".svg"/>
    <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    <remove fileExtension=".woff"/>
    <mimeMap fileExtension=".woff" mimeType="application/x-font-woff"/>
</staticContent>

Hope this helps others from wasting time looking for a fix.

Community
  • 1
  • 1
Jesse VanDerPol
  • 953
  • 1
  • 7
  • 15
  • 1
    Thanks for leaving your question up. Apparently it is more SEO friendly and was easier to find. – cdonner May 15 '14 at 14:13
  • 2
    You might also want to add the before the .json map, in case one of your server environments already has it mapped. – Geoff Jan 06 '15 at 18:45
0

I found that if you have any mimeMap items duplicated between your Web.Config in the directory hosting your app and the default %UserProfile%\Documents\IISExpress\config\applicationhost.config it will fail for them all.

Same solution worked: made sure to <remove> each <mimeMap> entry.

rburte
  • 627
  • 6
  • 11