Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 525
Pablo Avatar asked Sep 13 '12 01:09

Pablo


2 Answers

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.

like image 182
Jude Fisher Avatar answered Oct 05 '22 08:10

Jude Fisher


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
like image 38
Sandrino Di Mattia Avatar answered Oct 05 '22 09:10

Sandrino Di Mattia