Reputation: 53
I'm having this weird issue with CORS where it works if I turn off the authentication in my azure web app service.
Setup:
I configured to add the headers globally via the global.asax.
Context.Response.AddHeader("Access-Control-Allow-Origin", "*");
Context.Response.AddHeader("Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept,MaxDataServiceVersion");
Context.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
Context.Response.AddHeader("Access-Control-Allow-Credentials", "true");
Results:
I did allow all origins just to see if the headers are added, but it keeps blocking it somehow for the authentication url.
Has anyone encountered this before? or am I missing a setup somewhere?
Thanks in advance.
Upvotes: 2
Views: 2480
Reputation: 24529
I think you cannot define multiple origin site via the web config? Is there a way to do this just with web. config or a custom code is needed to achieve this?
We could enable CORS for Azure WebApp easily with Azure portal. You use * to allow all origins to make cross-orgin calls. We could get more information about azure webapp CORS from this tutorial.
Cross-Origin Resource Sharing (CORS) allows JavaScript code running in a browser on an external host to interact with your backend. Specify the origins that should be allowed to make cross-origin calls (for example: http://example.com:12345). To allow all, use "*" and remove all other origins from the list. Slashes are not allowed as part of domain or after TLD.
Update:
This is a known limitation of the Azure Portal which should be fixed in the future.
As you mentioned that on the allows-credentials with CORS thing. It's not supported if you use the portal CORS feature, but if you disable it (by removing all the domains there), you can handle CORS inside your code and customize it
For more information, please refer to this blog.
Upvotes: 2