Pablo
Pablo

Reputation: 2386

Azure and .json mimeType without web.config

Adding to my web.config

<system.webServer>
  <staticContent>
    <mimeMap fileExtension=".json" mimeType="application/json" />
  </staticContent>
</system.webServer>

Allows my application to run on Azure, but will crash my remote IIS server because its already included. Removing the remote IIS mimeType is not practical in this particular case. I end up using a different web.config

Is there another mechanism by which I can configure Azure IIS mimeType so I don't have this problematic web.config?

I would like a single deployment package that will work on Azure and non Azure.

Upvotes: 8

Views: 6799

Answers (2)

Jude Fisher
Jude Fisher

Reputation: 11294

This should work:

<system.webServer>
  <staticContent>
    <remove fileExtension=".json" />
    <mimeMap fileExtension=".json" mimeType="application/json" />
  </staticContent>
</system.webServer>

See also 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

This doesn't make any difference to your overall IIS configuration, it just conditionally removes the mimeMap from the configuration of this particular site (as governed by this web.config) before adding it again.

Upvotes: 20

Sandrino Di Mattia
Sandrino Di Mattia

Reputation: 24895

You can create a startup task that adds the mime type on IIS level. This way you won't need to include it in your web.config:

"%windir%\System32\inetsrv\appcmd.exe" set config /section:staticContent /+"[fileExtension='.json',mimeType='application/json']"
exit /b 0

Upvotes: 3

Related Questions