且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

你怎么把环境变量在web.config中?

更新时间:2021-10-21 09:46:41

&LT值;&的appSettings GT; 只是字符串。如果你想要的环境变量来扩大你的应用程序将需要做的本身。

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.

这样做的一个常用方法是使用 CMD 语法%变量%,然后用Environment.ExpandEnvironmentVariables$c$c>扩大它们。

A common way of doing this is to use the cmd syntax %variable% and then using Environment.ExpandEnvironmentVariables to expand them.

的规则是不同的(见问题链接):但这些值似乎是在环境变量的话,在配置文件中:

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%'/>

,然后检索:

var someSetting = Environment.ExpandEnvironmentVariables(
                     ConfigurationManager.AppSetting("SomeSetting"))

可以很好地工作。

may well work.