无法添加 header/Access-Control-Allow-Crendentials - python 功能应用

can't add header/Access-Control-Allow-Crendentials - python function app

通过使用网络设置主机,我可以让我的信号器代码连接 + 在我的本地环境中正常工作 url

  "Host": {
    "LocalHttpPort": 7070,
    "CORS": "http://localhost:4200",
    "CORSCredentials": true
  }

然后我将它部署到门户并转到 CORS 并添加网络 url,我的存储 blob 静态网站托管在 CORS 内部,用于 signalr 函数应用程序。当我使用网络 url 匹配 cors 值登录到我的应用程序时,出于某种原因我得到了这个

另外根据 docs(页面底部)我必须启用 Access-Control-Allow-Crendentials

但 python 上的函数应用程序 运行 似乎没有该选项

如何在 python 函数应用程序中启用 Access-Control-Allow-Crendentials

是的,在azure portal上没法设置。当您基于 linux 网络应用程序时,不仅 'Access-Control-Allow-Crendentials',还有许多其他配置设置无法使用 azure 门户设置。

为了实现你想要的,你可以在powershell中使用下面的cmd:(当你基于azure web app时它可以工作。azure function是基于web app sandbox的,所以下面的cmd也可以在函数上工作。)

az resource update --name web --resource-group yourresoursegroupname --namespace Microsoft.Web --resource-type config --parent sites/yourfunctionname --set properties.cors.supportCredentials=true

这是官方文档:

https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-rest-api#enable-cors

If your app requires credentials such as cookies or authentication tokens to be sent, the browser may require the ACCESS-CONTROL-ALLOW-CREDENTIALS header on the response. To enable this in App Service, set properties.cors.supportCredentials to true in your CORS config. This cannot be enabled when allowedOrigins includes '*'.

在我这边,我可以更改配置设置。让我知道您是否可以更改配置。:)