const string policyName = "CorsPolicy";
//添加跨域配置,加载进来,启用的话需要使用Configure
services.AddCors(options =>
options.AddPolicy(policyName, builder =>
{
builder
.AllowAnyHeader()
.AllowAnyOrigin()
.AllowAnyMethod();
//builder.AllowCredentials(); 该方法不能和AllowAnyOrigin 同时使用,否则会触发异常:The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time. Configure the CORS policy by listing individual origins if credentials needs to be supported
})
);
const string policyName = "CorsPolicy";
//支持跨域
app.UseCors(policyName);