我正在构建我的第一个Function App,所以如果我问了一个愚蠢的问题,请记住这一点:)
我需要在运行时存储一些设置。
在标准桌面应用程序中,我可以轻松地使用以下方式更新app.config
:
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["UserId"].Value = "myUserId";
config.Save(ConfigurationSaveMode.Modified);
但是在 Function App 中,我使用ConfigurationBuilder
加载配置:
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
该配置对象无法进行更新。在本地开发时,可以更新local.settings.json文件,但在Azure上运行时,所有内容都从“应用设置”(环境变量)中加载。
我的问题是:如何更新与我的函数应用相关联的“应用设置”中的单个值?
我找到了一个类似的问题,但其中的解决方案需要注册AAD中的应用程序,并且它会更新所有设置,而不仅仅是一个值。