I wrote some code to handle CORS
into my Web Api
(.Net Core
). These code perfectly works on my local and test server(Azure app service) but it is not working on production(Azure app service). It gives error-
XMLHttpRequest cannot load http://myapiproduction.co/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://myuidashboard.co' is therefore not allowed access.
I gave correct allowed origin url in appsettings.Production.json
. I removed all value (*
) from CORS
section of Azure app service(Production env).
When we removed every thing from CORS section of app service then our code logic should work because at a time only one middleware will work either app service's CORS middleware or our Web Api code logic.
Web Api (Startup.cs
)-
var allowedOriginsArr = Configuration["AppSettings:AllowedOrigins"].Split(','); //Example- "http://myuidashboard.co"
services.AddCors(options =>
{
options.AddPolicy("AllowAllCorsPolicy",
builder => builder.WithOrigins(allowedOriginsArr)
.WithMethods("GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS")
.AllowAnyHeader()
.WithExposedHeaders("X-Auth-Token")
.AllowCredentials());
});
So, my question is - Is there any other setting i have to do to disable CORS middleware of Azure app service? I want to control CORS
completely by code (Api logic).