Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS only add MIME if not exist

Tags:

mime-types

iis

I have - again - a problem in my WebAPI application.

I am trying to deploy on different versions of IIS (7, 7.5, 8). Newer versions seem to have a global MIME handler for .json, while older versions don't.

When IIS finds no MIME handler, the file does not exist. So, for the older version I made a local MIME handler in web.config. The tricky part is: if it finds two of them (one global and one local), it stops working - even if they both are the same, IIS does not know which one to choose (wtf!?) and only throws errors.

Is there a switch I can apply in web.config which states that the MIME is only to be used if there is no other MIME for this extension available?

If not, can I tell VisualStudio to deploy different versions of web.config, depending on the deployment profile - and/or can I apply a IIS-version-based switch in web.config?

like image 650
Alexander Avatar asked Jan 12 '23 16:01

Alexander


1 Answers

The easiest way to deal with this is to use the remove option for a mime mapping like this:

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

It's discussed in detail here:

http://blogs.msdn.com/b/chaun/archive/2009/12/04/iis7-error-cannot-add-duplicate-collection-entry-of-type-mimemap-with-unique-key-attribute-fileextension.aspx

There's also a reference to it here: Add MIME mapping in web.config for IIS Express

like image 55
Steven M. Cherry Avatar answered Jan 18 '23 15:01

Steven M. Cherry