【问题标题】:How to Disable Azure Web App from overwriting CORS如何禁止 Azure Web App 覆盖 CORS
【发布时间】:2019-02-10 23:53:12
【问题描述】:

我有一个 .NET Core 2.1 应用,并且在 ConfigureServices 中添加了 CORS 策略:

services.AddCors(options => options.AddPolicy("CorsPolicy",
            builder =>
            {
                builder.AllowAnyMethod().AllowAnyHeader()
                       .WithOrigins("http://localhost:4200")
                       .AllowCredentials();
            }));

然后在Configure

app.UseCors("CorsPolicy");

在本地,这很好用。当我部署到我的 Azure Web 应用程序时,它不起作用。我的客户得到:

"对预检请求的响应未通过访问控制检查:响应中的 'Access-Control-Allow-Credentials' 标头的值为 '',当请求的凭据模式为 'include 时必须为 'true' '"

我可以通过在本地删除 .AllowCredentials() 行来重新创建确切的错误。

我从文档中了解到 Azure CORS 会接管任何代码 CORS:

“不要尝试将应用服务CORS和你自己的CORS代码一起使用。一起使用时,应用服务CORS优先,你自己的CORS代码无效。”

我似乎无法阻止 Azure Web Apps 接管。我尝试使用 CLI 删除 CORS,但无法完全摆脱它。

az resource update --name web --resource-group MyGroup --namespace Microsoft.Web --resource-type config --parent sites/MySite --set properties.cors.allowedOrigins="" --api-version 2015-06-01

所做的只是将 allowedOrigins 设置为空。但它仍在接管。如何从 Azure 中删除所有 CORS 痕迹,以便只使用我的代码?或者,在最坏的情况下,如何在 Azure 中执行相当于“AllowCredentials”的操作?

【问题讨论】:

    标签: azure .net-core cors azure-web-app-service


    【解决方案1】:

    我遇到了同样的问题,必须删除 Azure 门户中的 cors 选项卡下的所有“允许的来源”,以进行应用服务并重新启动。

    如果这不起作用,这里有一些关于删除 web 配置中的选项标头的建议 Enable Access-Control-Allow-Credentials header in Azure website (Azure App Services)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      • 2012-07-25
      • 2012-10-12
      • 2023-04-04
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多