In ASP.NET 5, how do we programmatically access an Azure Web App's connection strings? I've been able to retrieve the TEST_APP_SETTINGS value but not the TestConnString one.

Here is what I have tried:
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
I'm afraid that AppSettings doesn't exist. I've also done this and the app settings show up but the connection strings do not.
Startup.cs
// Setup configuration sources.
Configuration = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
// Allow access from *.cshtml
services.AddSingleton<Configuration>(provider =>
{
return Configuration as Configuration;
});
Dev.cshtml
@inject Microsoft.Framework.ConfigurationModel.Configuration config;
<dl>
@foreach(var k in @config.GetSubKeys())
{
<dt>@k.Key</dt>
<dd>@config.Get(k.Key)</dd>
}
</dl>
The connection strings are set as environment variables. Therefore, first you have to add the environment variable configuration source and then the connection strings will be named Data:NAME:ConnectionString where NAME is the name of the connection string in the portal.
For example, if your connection string is "ServerConnection" then you access it using using Data:ServerConnection:ConnectionString
Here are the tests that validate the mapping environment configuration mappings, they might explain it better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With