Serving .JSON Files in Azure gives a 404

I just came across a problem when implementing some lovely localization in Javascript. Using the i18next library, it requires that all of your translations be stored in .json files. No problem! Everything runs fine locally (of course) but once I had pushed to my staging environment, those .json files couldn’t be found! When accessing the files directly, I was greeted with a 404. Because everything worked locally I knew the paths were just fine, so after a quick Google this looked to be a MIME issue. IIS didn’t know what to do with these static files so just threw up a 404.

The first solution was to add the missing MIME types to my web.config, like so:

<system.webServer>
  <staticContent>
    <remove fileExtension=".json" />
    <mimeMap fileExtension=".json" mimeType="application/json; charset=UTF-8" />
 </staticContent>
</system.webServer>

Redeploy, refresh. Now I had a bunch of errors with other scripts that were working fine, almost every script was throwing a 500 error. More Googling and cussing and publishing and refreshing and nothing. Eventually I spotted a small note on someone’s post on StackOverflow where they mentioned changing the BuildAction for the .json files to ‘Content‘ instead of ‘None’. I’m not sure what affect this has and will look in to it another time, but for now it solves my problem and hopefully yours too!

One thought on “Serving .JSON Files in Azure gives a 404

  1. Hello

    I’ve tried your solution above, but it still tries to serve json as text/html and gives a 404.

    Did you find out anything further from the post above?

    Regards

    Stuart

Leave a Reply

Your email address will not be published. Required fields are marked *