Skip to content

CORS policy not work #3102

Closed
Closed
@AuthorProxy

Description

@AuthorProxy

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions