Closed
Description
server error: A CORS policy named 'CorsPolicy' could not be found.
client error:
xhr.js:178 OPTIONS http://05b9f069.ngrok.io/api/somemethod 500 (Internal Server Error)
btrips:1 Failed to load http://05b9f069.ngrok.io/api/somemethod: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 500.
ConfigureServices method:
void ConfigurePolicy(CorsPolicyBuilder builder)
{
builder
.WithOrigins("http://localhost", "http://localhost:3000")
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
}
services.AddCors(options =>
{
options.AddPolicy(StartupConstants.CorsPolicy, ConfigurePolicy);
});
services.AddMvc()
Configure method
app.UseCors(StartupConstants.CorsPolicy);
app.UseMvc();