Configuring Inter netcore3.0

netcore3.0 frame has integrated Microsoft.AspNetCore.Mvc.Cors bag, so no separate reference.

In ConfigureServices add Cors policy Service

services.AddCors(options =>
{
    options.AddPolicy("AllowAllOrigins",
        builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials());
});

Adding to the middleware in the Configure

  app.UseCors("AllowAllOrigins");

[Note: Policy name can be customized but must correspond to the front and back, of course, you can set up multiple strategy]

"" "Do you think this will end? Run up to find the error:

 

The reason is that the new version of Cors has prevented the use of middleware allows arbitrary Origin, meaning that even if you configure the AllowAllOrigin () will not take effect. The solution is to use WithOrigins set:

policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().WithOrigins(new []{"http://localhost:5000"});

Guess you like

Origin www.cnblogs.com/az4215/p/11910346.html