47

My first Azure website is a simple test site I've had for a while that makes ajax calls back to the server for JSON data. All the data files have .json extensions. Azure will not 'see' these files. If I change the extension to .txt it servers them up fine.

Do I have to muck with IIS to get this .json to be seen?

Luis Gouveia
  • 8,334
  • 9
  • 46
  • 68
Pablo
  • 2,376
  • 5
  • 26
  • 34
  • duplicate of http://stackoverflow.com/questions/6273607/windows-azure-serve-unknown-mp4-mime-types-in-windows-azure-iis-storage – Dennis Burton Sep 12 '12 at 01:18

4 Answers4

52

Citing Ahmed Sabbour with his blog post http://blogs.msdn.com/b/africaapps/archive/2013/06/07/how-to-serve-static-json-files-from-a-windows-azure-website.aspx you have to do the following:

"If you upload a .json file to your Windows Azure website and try to access it, it would give you a 404 File Not Found error, because the MIME Type of .json is not set by default. This also applies in general to any file that might need a specific MIME Type.

To fix this issue, FTP into your website and upload the following Web.config file which will set the correct MIME types. If you already have a Web.config file in place, just add the below to the appropriate section.

<?xml version="1.0"?>

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

". I did this and the 404 was gone.

Klaas
  • 22,394
  • 11
  • 96
  • 107
  • This unsets everything else already set in IIS. If you have CSS, JS or images, there's a good chance you'll have to re-declare them all in this section of your web.config file. – Simon Germain May 15 '18 at 17:20
  • Just to complement this very good answer, if you're working with react, copy this web.config to the build folder (with npm react build )in the following way (credits to Liviu Costea): https://medium.com/hackernoon/adding-web-config-to-react-projects-3eb762dbe01f – Luis Gouveia Jun 30 '20 at 17:38
51

I too found Ahmed Sabbour's blog post helpful, but it created an additional problem for me. Whilst the fix worked for the Azure Web App when I then tried to run the app locally it died horribly, throwing HTTP 500.19 everywhere. It took me a while to figure out how to fix this whilst maintaining a single web.config. The solution was (albeit a bit of a fudge) to remove the fileExtension first and then add it back in:

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

For my narrow purposes this was fine and I hope this might save someone time trying to figure this out.

Mike Rouse
  • 1,278
  • 18
  • 34
3

It appears that Azure (Cloud Services, at least) knows how to serve JSON from a deployed ASP.NET MVC project. The problem in my case was that the Build Action on the JSON file's property page was not set correctly. Changing the Build Action to Content fixed it for me.

Todd
  • 12,995
  • 3
  • 30
  • 25
  • 1
    Thank you for this. I've been pulling my hair out trying to figure out why my manifest.json file was getting a 404 error, thinking it was a mime type issue, when really this was my problem; the build action was set to none. – Redit0 Dec 11 '19 at 12:05
  • how do you set the build action properly? – Manuel Castro Nov 01 '21 at 11:15
1

have you tried adding the specific MIME type to your server's config file?

http://www.iis.net/configreference/system.webserver/staticcontent/mimemap

If you add the mime type as application/json; charset=utf that should work.

Mu Mind
  • 10,935
  • 4
  • 38
  • 69