How to fix “The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time” error

后端 未结 7 897
再見小時候
再見小時候 2021-02-03 17:10

I\'ve already enabled CORS on the project in C# .net Core

In startup.cs I\'ve added lines

...
services.AddCors();
...
app.UseCors(builder =         


        
7条回答
  •  野的像风
    2021-02-03 17:42

    I also faced same issue, and I found solution here:

    Setup Any Origin And Any Credentials

    Change your CORS setup in startup.cs file like this

    public void ConfigureServices(IServiceCollection services)
    {
        // ...
        services.AddCors(options =>
        {
            options.AddDefaultPolicy(builder => 
                builder.SetIsOriginAllowed(_ => true)
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials());
        });
    }
    

    It works for me.

提交回复
热议问题