我使用的是ANGLE和ASP.NET API.我面临的问题是:当我在API代码中添加CORS时,它可以在Internet Explorer上运行,但不能在Chrome和Firefox上运行.
以下是错误:
XMLHttpRequest无法加载http://localhost:41028/api/values/abc.这个
以下是我在web.config
文件中添加的代码:
<system.webServer>
...
<httpProtocol>
<customHeaders>
<!-- Adding the following custom HttpHeader will help prevent CORS errors -->
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
...
</system.webServer>
在WebApiConfigFile.cs
文件中,我添加了:
var CorsAttribute = new EnableCorsAttribute("* ","* ", "* ");
config.EnableCors(CorsAttribute);
我是第一次使用CORS.如有任何帮助,我们将不胜感激.