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

会有一股神秘感。 提交于 2021-01-27 19:07:28

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/7943270/how-to-serve-json-files-from-iis7-when-request-is-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!