无法添加header/AccessControlAllowRendentials python函数应用程序

2024-05-16 01:42:25 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

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

enter image description here

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

enter image description here

但在python上运行的函数应用程序似乎没有这个选项 enter image description here

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


Tags: 函数代码web应用程序httphosturlaccess
1条回答
网友
1楼 · 发布于 2024-05-16 01:42:25

是的,没有办法在azure portal上设置它。当您基于linux web app时,不仅“访问控制允许Crendentials”,而且许多其他配置设置无法通过使用azure portal进行设置

为了达到您想要的效果,您可以在powershell中使用below cmd:(当您基于azure web app时,它可以工作。azure函数基于web app沙箱,因此below 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 '*'.

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

相关问题 更多 >