作者:手机用户2502940097 | 来源:互联网 | 2023-02-05 18:28
We are storing some of our sensitive keys and connection strings in the Connection strings section under the Web App application settings:
We retrieve configuration settings using the ConfigurationBuilder
:
COnfiguration= new ConfigurationBuilder()
.SetBasePath(environment.ContentRootPath)
.AddEnvironmentVariables()
.Build();
I would have expected AddEnvironmentVariables()
to pick up these connection strings, but it doesn't. Note that this does work if you set these values as "App settings" in the Web App.
Under closer inspection (using the Kudu console) I found that the environment variables being set for these connections strings have CUSTOMCONNSTR_ prefixed to the key name:
CUSTOMCONNSTR_MongoDb:COnnectionString=...
CUSTOMCONNSTR_Logging:COnnectionString=...
CUSTOMCONNSTR_ApplicationInsights:ChrOnosInstrumentationKey=...
我现在应该如何使用ConfigurationBuilder
?读取这些连接字符串?
编辑:
我发现一个方便的AddEnvironmentVariables
重载存在与prefix
参数,描述为:
// prefix:
// The prefix that environment variable names must start with. The prefix will be
// removed from the environment variable names.
但是添加.AddEnvironmentVariables("CUSTOMCONNSTR_")
到配置生成器中也不起作用!