CORS请求的资源上没有“Access-Control-Allow-Origin”标头

时间:2014-05-18 13:25:28

标签: c# javascript web-services cors

我收到以下错误:

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>

1 个答案:

答案 0 :(得分:3)

尝试使用此..

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