无法在 IIS 下使用 dotnet 配置分层设置

Unable to configure hierarchical settings with dotnet under IIS

对于我们的 dotnet 应用程序,我们有一个使用分层设置的 appsettings.json 文件,例如:

"mysection": { "myproperty": "my secret value" }

此 appsettings.json 用于开发目的。

在生产模式下,我们使用 Azure Keyvault(因为我们的应用程序在 Azure 下 运行) 在 keyvault 中,Secret 定义为

mysection--myproperty

但是现在,我们需要在IIS下部署同样的webservice。我们想在 IIS 设置下定义秘密值,但 mysection--mypropertymysection:myproperty 不起作用。

您知道如何在 IIS 下设置此层次结构吗?

使用环境变量时,小节需要用双下划线分隔__

来自 the docs:

The : separator doesn't work with environment variable hierarchical keys on all platforms. __, the double underscore, is:

  • Supported by all platforms. For example, the : separator is not supported by Bash, but __ is.
  • Automatically replaced by a :

这意味着您需要将 mysection--myproperty 更改为

mysection__myproperty

正确解析。

此外,您可以使用 IConfigurationRoot.GetDebugView() 查看配置值的来源。