I'm serving .JSON files, but even though the file exist, IIS keeps throwing 404 error when any of the file is accessed. I tried renaming one of the file to .JS, and it works.
Any pointer what setting can cause this issue?
I'm serving .JSON files, but even though the file exist, IIS keeps throwing 404 error when any of the file is accessed. I tried renaming one of the file to .JS, and it works.
Any pointer what setting can cause this issue?
By default, IIS in W2K3 and above won't serve files that aren't of a MIME type that it knows about (instead returning 404 errors).
You need to add a MIME type to IIS to allow it to serve that type of file. You can set it at the site level or at the server level.
To set this for the entire server:
I had the same problem. IIS does something called MIME type filtering. If it dosn't know a specific file extension's MIME type, it returns a 404 error.
On IIS <7: Open the site (or server) properties. Click on the HTTP-Header tab. Click on the MIME Types button. Add the file type * with the MIME type "application/octet-stream".
For IIS 7: Open IIS manager. Click the server or website. Double-click the MIME Types feature icon. In the Actions pane, click Add. Populate the "File Name Extension" box with * and the MIME Type box with "application/octet-stream".
I added MIME type .json
- text/json
to the site in IIS to view in browser as text.
To consolidate answers into one more general answer:
Here comes the caveat:
If you're experiencing this sort of problem, open up the website's web log files, and have a look at the sub-status code (i.e. 404 3) to determine exactly why your website isn't serving content for IIS 6, or
in IIS 7.
I had this problem too - and the problem turned out to be file permissions on the folder where the json file was stored. I answered a similar question here.
These folks are all correct to say you need to add the MIME type.
The MIME type enables the file extension on the server and the Mapping Handler tells IIS what to do with it.
So you also have to add the Mapping Handler, and for that you have to have the Windows Feature called Classic Asp installed in order to handle the mapping.
Handler Mappings
Add a Script Map
*.json
C:\WINDOWS\system32\inetsrv\asp.dll
JSON
(you can call it anything you like)Also, some folks will tell you to use `application/x-javascript' as the mime-type application, but JSON is not javascript, per se (it is a subset, however) and so it should be 'application/json' instead, as it is that IANA-registered media type for JSON.