IIS 7 and Above
API is throwing CORS Error on one server but running well on another(...
Last post Oct 16, 2017 06:41 AM by Yuk Ding
Oct 13, 2017 03:20 PM|rf_khan|LINK
I have created a web API in the asp.Net core and enabled cors in the startup.cs file. After deployment windows server APIs are accessible via AJAX from another domain. But when I am hosting the APIs on another windows server it is throwing the following
"Failed to load
http://someDomian/api/APIName: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:57515, *', but only one is allowed. Origin 'http://localhost:57515'
is therefore not allowed access."
I am wondering why APIs are giving errors on one web server while they are accessible from another web server.
Thanks in advance.
Oct 16, 2017 06:41 AM|Yuk Ding|LINK
I checked this link:
And it find someone with the similar case. You could just try this in WebApiConfig.cs.
var cors = new EnableCorsAttribute("*", "*", "*");
Or maybe you could try to use IIS HTTP RESPONSE HEADER or URL rewrite.