从2.2 .Net Core迁移到3.0 Cors错误

时间:2019-11-08 13:11:20

标签: asp.net-core migration asp.net-core-webapi .net-core-3.0 asp.net-core-3.0

在将API从2.2 .NET Core迁移到3.0时,我在运行API时遇到以下代码错误。

公共静态void配置(IApplicationBuilder应用)

{

app.UseCors(builder => builder

                  .WithOrigins(ConfigurationSettings.CORSAllowedSites)
                  .AllowAnyMethod()
                  .AllowAnyOrigin()
                  .AllowAnyHeader()
                  .AllowCredentials()
                  );

}

**错误:CORS协议不允许同时指定通配符来源和凭据。 如果需要支持凭据,则通过列出各个来源来配置Cors策略**

1 个答案:

答案 0 :(得分:0)

.AllowCredentials()方法中删除app.UseCors,如下所示:

  app.UseCors(builder => builder
                      .WithOrigins(ConfigurationSettings.CORSAllowedSites)
                      .AllowAnyMethod()
                      .AllowAnyOrigin()
                      .AllowAnyHeader()
                      );