How do you put environmental variables in web.config?
For Applications, including Web Applications, On Windows:
The values in <appSettings>
are just strings. If you want environmental variables to be expanded your application will need to do that itself.
A common way of doing this is to use the cmd
syntax %variable%
and then using Environment.ExpandEnvironmentVariables
to expand them.
On Azure:
The rules are different (see links in the question): but the values appear to be in environment variables so, in the config file:
<add key='SomeSetting' value='%APPSETTING_some_key%'/>
and then to retrieve:
var someSetting = Environment.ExpandEnvironmentVariables( ConfigurationManager.AppSetting("SomeSetting"))
may well work.