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=...
How should I now read in these connection strings using the ConfigurationBuilder?
EDIT:
I found that a handy AddEnvironmentVariables overload exists with a prefix parameter, described as:
// prefix:
// The prefix that environment variable names must start with. The prefix will be
// removed from the environment variable names.
But adding .AddEnvironmentVariables("CUSTOMCONNSTR_") to the configuration builder doesn't work either!
