You can use CloudConfigurationManager.GetSetting for AppSettings, what is the equivalent approach for Connection Strings You can use CloudConfigurationManager.GetSetting for AppSettings, what is the equivalent approach for Connection Strings azure azure

You can use CloudConfigurationManager.GetSetting for AppSettings, what is the equivalent approach for Connection Strings


Note that in order to use CloudConfigurationManager to read from an app.config file, you must specify the configuration settings in the appSettings tag... Only configuration settings within the appSettings tag can be read by CloudConfigurationManager.

Per this article on MSDN


I just came across the AmbientConnectionStringProvider in one of MSFT's github accounts. Which in turn is using a ConfigurationUtility class.ConfigurationUtility is then doing this:

public static string GetConnectionFromConfigOrEnvironment(string connectionName){    string configValue = null;    var connectionStringEntry = ConfigurationManager.ConnectionStrings[connectionName];    if (connectionStringEntry != null)    {        configValue = connectionStringEntry.ConnectionString;    }    if (!string.IsNullOrEmpty(configValue))    {        // config values take precedence over environment values        return configValue;    }    return Environment.GetEnvironmentVariable(connectionName) ?? configValue;}

This approach may be what I was looking for.


As it turns out, I can use regular ol' ConfigurationManager for both my AppSettings as well as ConnectionStrings.
It's smart enough to know when I'm running in Azure and when I'm running locally.

More details available here: https://azure.microsoft.com/en-us/blog/windows-azure-web-sites-how-application-strings-and-connection-strings-work/