Access-Control-Allow-Origin

No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
当使用ajax访问远程服务器时,请求失败,浏览器报如上错误。这是出于安全的考虑,默认禁止跨域访问导致的。

解决方法 :
web.config中配置:

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
        <add name="Access-Control-Allow-Methods" value="GET,POST, PUT, DELETE,OPTIONS" />
        <add name="Access-Control-Allow-Credentials" value="true" />
        <add name=".json" value="application/x-javascript" />
      customHeaders>
    httpProtocol>s
    <validation validateIntegratedModeConfiguration="false" />
  system.webServer>

你可能感兴趣的:(ASP.NET)