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
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>
2 Comments
user593733
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.
JConstantine
This works great, be aware you may also need to add
<remove fileExtension=".json" /> before hand to prevent a conflict