11

I have a json file that I would like to include as content to my MVC 4 Web Application. I add the file to my Content folder and mark 'Build Action' as 'Content' and 'Copy to Output Directory' as 'Do not copy'. Now if I browse to http://[my site]/content/myjsonfile.json I get an HTTP 404. I mess around with all of the build actions and copy to output selections and still doesn't work. I change the json file extension to txt and then it works. Is this a bug? My site is published using Windows Azure. Thanks for any feedback.

1 Answer 1

24

The problem is that your webserver doesn't recognize the filetype. Add this line to your web.config:

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

    </staticContent>
</system.webServer>
Sign up to request clarification or add additional context in comments.

2 Comments

I added the web.config settings and my files were still not published? I changed the Build Action to 'Content' with 'Copy to Output Directory' as 'Do not copy' and that published them. I verified this with several files.
This works great, be aware you may also need to add <remove fileExtension=".json" /> before hand to prevent a conflict

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.