[当我尝试从客户端访问WEB API时,出现CORS错误。
为此,我在IIS中添加CORS Access-Control-Allow-Origin:*:
但是在添加Access-Control-Allow-Origin:*
之后,我在客户端收到此错误:
localhost/:1 Access to XMLHttpRequest at 'http://localhost/fridge/api/user/15' from origin 'http://localhost:4200' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:4200, http://localhost:4200', but only one is allowed.
任何想法如何解决以上错误?为什么会出现此错误?
好像您添加了两个标题条目。
您可以尝试删除WebApiConfig.cs或web.config cors条目。
另一种方法是,您可以尝试添加确切的域而不是*。
var CorsAttribute = new EnableCorsAttribute("http://www.example.com","", ""); config.EnableCors(CorsAttribute);
如果您使用webservice(.asmx)作为API
[从Global.asax.cs文件的begin_request函数或web.config中删除'Access-Control-Allow-Origin'详细信息。