10

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?

6 Answers6

22

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:

  • Open the properties for the server in IIS Manager and click MIME Types
  • Click "New". Enter "JSON" for the extension and "application/json" for the MIME type.
Evan Anderson
  • 142,957
3

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".

2

I added MIME type .json - text/json to the site in IIS to view in browser as text.

1

To consolidate answers into one more general answer:

Here comes the caveat:

  • Unless a script handler (active content engine, eg, ASP/ASPX/PHP/Java/ISAPI/etc) is associated with them
    • this means that IIS treats them as active content, not static files
  • Active content files served by any extension must have that extension allowed in the Web Service Extensions restriction list (aka ISAPI/CGI restrictions in IIS 7)
    • if you're getting a 404 on an active content type in IIS 7, it may also mean your handler is not installed - so you need to actually go install the component that supports that file extension (for example, if .aspx files generate a 404, you probably don't have ASP.Net installed)

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

  • use Failed Request Tracing
  • (or just the detailed errors on the local console)

in IIS 7.

TristanK
  • 9,173
  • 2
  • 30
  • 39
1

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.

Here is how to add the Mapping Handler:

  1. Open IIS7 Manager
  2. Go to the properties for IIS Server (or just the site, if you don't want a global setting)
  3. Click on Handler Mappings
  4. Click on Add a Script Map
  5. Enter the properties:
    • Request Path: *.json
    • Executable: C:\WINDOWS\system32\inetsrv\asp.dll
    • Name: JSON (you can call it anything you like)
  6. Click OK, and you are done. It should start working and you don't need an IIS reset.

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.

bgmCoder
  • 726
0

Also check Request Filtering in IIS. If ".json" is there and blocked, nothing else will work.

enter image description here

Glen Little
  • 495
  • 3
  • 7
  • 18