简体   繁体   中英

How To Serve .json files from IIS7 when request is POST

I have an asp.net 4.0 web site that needs to serve files of type .json. The request is coming in as a POST, which does not work. GET works fine. Anyone know what configuration I need to change to make this work?

You probably already found the answer, but I think the problem lies in that you need to add a ".json" handler for your web server...

By default IIS is not configured to handle .json extension.

You can apply the mime type as a handler on the root of IIS so .json can be handled by every site or virtual folder in the IIS or just to the specific site.

  1. Open IIS Manager
  2. Display properties for the IIS Server
  3. Click MIME Types and then add the JSON extension:
    • File name extension: .json
    • MIME type: application/json
  4. Go back to the properties for IIS Server
  5. Click on Handler Mappings
    • Add a script map
    • Request path: *.json
    • Executable: C:\\WINDOWS\\system32\\inetsrv\\asp.dll
    • Name: JSON

( or Apache, if you're on the dev side... )

Apache Module mod_mime AddType

Note: In Ubuntu you ALSO need to edit the file /etc/mime.types and add the line:

application/json json

Then restart Apache

sudo /etc/init.d/apache2 restart

GET or POST is irrelevant, its got nothing to do with the type of response your program sends. There is no setting that would make a difference. Your problem is a logic error in your program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM