这是此问题的后续问题:
appsettings.json and azure function by timer
我想要动态设置,无需重新部署 Azure 函数即可更改这些设置。
链接的问题引用了一篇短文: https://medium.com/awesome-azure/azure-reading-application-settings-in-azure-functions-asp-net-core-1dea56cf67cf
我从文章中了解了如何处理用于使用 local.settings.json 文件进行本地调试的本地设置。我不明白的是在云中运行时我需要做什么来添加设置以及如何准确读取它们。
所以我的问题是:
如何添加在 Azure 中运行时读取的设置(从文章中不确定图片中的“应用程序设置”是什么)?
使用
var value = Environment.GetEnvironmentVariable("your_key_here");
是否适用于本地环境以及在 Azure 中运行时?如何从外部更改其中一项设置,而无需重新部署该函数?
我上面链接的文章显示了在 run 方法中创建配置变量的代码。我还需要将它添加到某个地方吗?既然 key 位于 azure 中的应用程序设置中或用于本地开发的 json 文件中,为什么需要此代码?我不能在 Run 方法中也使用
GetEnvironmentVariable
吗?
最佳答案
在代码中,从环境变量中读取设置。然后...
- 对于本地开发,您可以在 local.settings.json 文件中添加设置。
- 在 Azure 中,在应用程序设置中添加同名的设置
- 应用设置覆盖 settings.json
App settings in a function app contain configuration options that affect all functions for that function app. When you run locally, these settings are accessed as local environment variables.
和
The function app settings values can also be read in your code as environment variables.
- 通过将它们添加到 Function App 的应用程序设置中
- 是的。
- 在“应用程序设置”中更改它(将会重新启动)
Can't I just use
GetEnvironmentVariable
also in the Run method
4. Yes, you can. Adding it to a config variable enables you to read it more easily in multiple locations.
要使用更集中的方式来处理设置并且不重新启动应用程序(如果您不希望这样做),请查看 App Configuration .
关于c# - 在Azure功能中使用appsettings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71749052/