分享

Get IIS to serve JSON files (inc. POST,GET)

 和帅书馆 2016-10-13

W2K3下配置IIS6支持.json格式文件:

   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. 
  • 大概意思:打开IIS管理器,右键【属性】进入【MIME类型】,添加一项【json】扩展类型【application/json




win7下配置iis支持.json格式的文件:


1、IIS必须开启ASP支持,打开或关闭windows功能——internet信息服务——万维网服务——应用程序开发功能,选择asp,然后确定。


2、Internet信息服务管理器,打开”MIME类型“。点击添加,扩展名写“.json”,MIME类型写”application/x-JavaScript“【不要引号】,然后确定。


3、打开”处理程序映射“,点击”添加脚本映射“,请求路径写”*.json”【不要引号】,可执行文件为“C:\Windows\System32\inetsrv\asp.dll”【通过浏览窗口定位该文件】,名称写“JSON”,再打开请求限制——谓词——下列谓词之一,填写“GET,POST”【不要引号】,两次确定后会弹出提示,点击“是”,然后重启IIS【cmd->"iisreset"】。


4、通过浏览器访问:http://localhost/xxx.json,应该就可以显示json数据了


配置VS IIS Express,支持JSON:

方法有2种:

1. 命令行

  a. cd "iis express的安装目录"  例如:cd C:\Program Files (x86)\IIS Express

  b. appcmd set config /section:staticContent /+[fileExtension='.json',mimeType='application/x-javascript']

  c. appcmd set config /section:handlers /+[name='JSON',path='*.json',verb='GET,HEAD,POST,DEBUG',modules='IsapiModule',scriptProcessor='%IIS_BIN%\asp.dll', resourceType='File']

2. 直接修改配置文件(不建议使用,容易找错配置文件的位置)

  正确路径在:%UserProfile%\Documents\IISExpress\config\applicationhost.config

  a. 在<handlers>节点下面添加:<add name="JSON" path="*.json" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%IIS_BIN%\asp.dll" resourceType="File" />

  b. 在<staticContent>节点下面添加:<mimeMap fileExtension=".json" mimeType="application/x-javascript" />


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多