为 Azure Functions 本地主机配置 CORS

Configure CORS for Azure Functions Local Host

我正在使用 Azure Functions CLI 工具在本地测试 Azure Functions 应用程序。有什么方法可以为本地主机配置 CORS 设置吗?

你可以这样启动主机

func host start --cors *

您也可以更具体,并提供以逗号分隔的允许网址列表

更多信息:https://github.com/Azure/azure-webjobs-sdk-script/issues/1012

在 Azure Functions 上配置 CORS 的另一种简单方法是使用 Azure 门户,

1- 转到 Azure 门户中的功能应用程序设置

2 - 单击 CORS 并添加您的本地主机 url

给你!

希望这对某人有所帮助。

如果您在通过 Visual Studio 的调试 "Application Arguments" 传递参数时遇到问题。这是从命令行传递参数的方法:

1) 打开一个普通的命令提示符。

2) cd 到您的解决方案的已编译 dll,即 "Your Solution Path"\bin\Debug\netstandard2.0

3) 从命令行启动Azure函数运行时,即:

dotnet "C:\Users\USER\AppData\Local\Azure.Functions.V2.Cli\func.dll" host start --port 7071 --cors * --pause-on-error 

4) 要在 Visual Studio 中调试,调试-> 附加到进程.. 并附加到将成为 运行.

的 donet.exe

希望这有助于防止有人过度撞击他们的头...

您可以在 local settings file local.settings.json:

中配置 CORS
{
  "Values": {
  },
  "Host": {
    "CORS": "*"
  }
}

Settings in the local.settings.json file are used only when you're running projects locally