【问题标题】:CORS No 'Access-Control-Allow-Origin' header is present on the requested resourceCORS 请求的资源上不存在“Access-Control-Allow-Origin”标头
【发布时间】:2014-07-06 12:10:17
【问题描述】:

我收到以下错误:

XMLHttpRequest cannot load http://localhost:62574/ServiceClass.asmx?op=loadMarkersViaWebService. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:15540' is therefore not allowed access. 

所以我在 Web.Config 中添加了以下内容,但是错误仍然存​​在:

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="http://localhost:15540/"/>
  </customHeaders>
</httpProtocol>

【问题讨论】:

  • 我看到端口不匹配?
  • @Niels 否,应用程序使用 15540,而 Web 服务使用 62574
  • 在这里查看我接受的答案:stackoverflow.com/questions/22127442/…
  • @rikket ,找到解决方案了吗?我有同样的问题。

标签: c# javascript web-services cors


【解决方案1】:

尝试使用这个..

<httpProtocol>
 <customHeaders>
   <add name="Access-Control-Allow-Origin" value="*" />
   <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
 </customHeaders>
</httpProtocol>

【讨论】:

    猜你喜欢
    • 2017-04-11
    • 2022-07-28
    • 1970-01-01
    • 2020-02-13
    • 2017-08-19
    • 2021-07-17
    • 2016-05-20
    相关资源
    最近更新 更多