Last post Oct 25, 2017 09:09 AM by Edward Z
Oct 13, 2017 03:23 PM|yash_9teen|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 15, 2017 09:52 AM|thangchung|LINK
Can you show me the code in the Startup.cs file so that I can see what's happened to you?
Oct 25, 2017 09:09 AM|Edward Z|LINK
Could you share us how you enable Cors in Startuo.cs?
Based on the error message, it seems you add both
http://localhost:57515 and “*” at CORS set up. If so, I am afraid it will fail to request Asp.Net Core web api.
I made a test with below code, the domain http://localhost:59277 will hit CORS issue.
builder.WithOrigins("http://localhost:59277","*"); //http://localhost:59277 will fail to request web api
And, I suggest you try to configure like below code.
//builder.WithOrigins("http://localhost:59277","*"); http://localhost:59277 will fail to request web api
If you are not this scenario, it would be helpful if you could share us a simple demo to reproduce your issue.