c# - 在Azure功能中使用appsettings

标签 c# azure azure-functions appsettings

这是此问题的后续问题:

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 文件进行本地调试的本地设置。我不明白的是在云中运行时我需要做什么来添加设置以及如何准确读取它们。

所以我的问题是:

  1. 如何添加在 Azure 中运行时读取的设置(从文章中不确定图片中的“应用程序设置”是什么)?

  2. 使用 var value = Environment.GetEnvironmentVariable("your_key_here"); 是否适用于本地环境以及在 Azure 中运行时?

  3. 如何从外部更改其中一项设置,而无需重新部署该函数?

  4. 我上面链接的文章显示了在 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.

参见Use application settings .

  1. 通过将它们添加到 Function App 的应用程序设置中
  2. 是的。
  3. 在“应用程序设置”中更改它(将会重新启动)

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/

相关文章:

c# - 如何在 .Net 应用程序中使用 IE 代理服务器设置及其凭据

Azure Resource Graph API - 通过数据工厂获取资源表

python - 有没有办法在 Azure Functions 中延迟 QueueMessage?

c# - ASP MVC 将 ApplicationUser 添加到通用存储库

c# - Automapper null 集合变空

azure - 如何提供 Windows Azure 托管站点的自定义域名

c# - 是否可以从存储过程访问 Azure Blob?

c# - Azure Functions Kubernetes 找不到 local.settings.json

Azure 队列触发函数错误

c# - 从 C# 中查找 msform 上的所有控件