What I wanted to do was fairly simple you would think. Create static json file so browsers can cache output and you don’t have to poll the database for large chunks of data.
So I created a JSON file test.json with the content
[{"frut":1}]
(My actual files are in the region of 3mb)I went to http://domain.com/frut.json and I got an
error 404
404 – File or directory not found.
The resource you are looking for
might have been removed, had its name changed, or is temporarily
unavailable.First of all I was suprised.. the file was there, why not offer it for download or a 403 forbidden…
Okay. Google, end up at https://www.sencha.com/forum/showthread.php?33266-Some-Problem-with-JSON/page2#post_229858
So I tried
IIS7 configuration to support JSON: Using IIS manager: clock on IIS server (the main node on the left - where you see the machine name) 1. Add ‘json’ MIME Type * Double click on ‘MIME Types’ icon * Click ‘Add…’ link (under Actions section on the right side) In ‘Add MIMI Type’ window type: File name extension: .json MIME type: application/x-javascript * Click OK, You should see the .json MIME Type added to the list of the MIME Types list. 2. Add Script Map Handler for ‘json’ MIME Type * Double click on ‘Handler Mappings’ icon * Click on ‘Add Script Map…’ link (under Actions section on the right side) * In ‘Add Script Map’ window type: Request path: *.json Executable: C:\Windows\System32\inetsrv\asp.dll Name: JSON * Click OK (Message box pops up with a message: Do you want to allow this ISAPI extension?...etc ) Click Yes, You should see the .json extension added to the list of the Handler Mappings list
Okay.
Error 500
instead oferror 404
. Not understanding why… how, what on earth is going on.
I checked logs. nothing there. Just a vague mention of 500 on a request. that’s it. no details, no error logs. nothing.I’m at this point seriously starting to hate microsoft again.
Read a lot about request limits, but that’s not it becuase this file doesn’t even reach 1kb, let alone the 2gb limit.
Google more, end up with nothing to show for it.
The question
How do I get a simple JSON text file to show up in IIS 7.5 so I can request with an an ajax request without IIS killing itself over a simple text file.
Answer
The solution seems simple but is nigh impossible to find to get the desired behaviour out of IIS.
The solution is basically, don’t serve as application/x-javascript
but as text/json
Based on the answer at IIS Can’t Serve Certain File Extension
Using IIS manager: click on IIS server (the main node on the left – where you see the machine name)
- Add
json
MIME Type- Double click on
MIME Types
icon - Click
Add…
link (under Actions section on the right side)
In
Add MIME Type
window type:
File name extension:.json
MIME type:text/json
- Click
OK
, You should see the.json
MIME Type added to the list of the MIME Types list.
- Double click on
Now when you request the file it serve it as a regular text file, just the way you want it.
Attribution
Source : Link , Question Author : Tschallacka , Answer Author : Tschallacka