1#

转自:http://www.figers.com/Blog/2013/03/21/enable-access-control-allow-origin-in-iis6-iis7-for-webapi-calls/

To allow your newly created webapi web service calls to be accessed from ajax post calls from another website you need to enable this setting in either IIS6 or IIS7

IIS6


  • Open Internet Information Service (IIS) Manager
  • Right click the site you want to enable CORS for and go to Properties
  • Change to the HTTP Headers tab
  • In the Custom HTTP headers section, click Add
  • Enter Access-Control-Allow-Origin as the header name
  • Enter * as the header value
  • Click Ok twice




IIS7 – Add this to your web.config

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <configuration>
  3. <system.webServer>
  4.    <httpProtocol>
  5.      <customHeaders>
  6.        <add name="Access-Control-Allow-Origin" value="*" />
  7.      </customHeaders>
  8.    </httpProtocol>
  9. </system.webServer>
  10. </configuration>
复制代码