问题描述
我目前的的,而我想打电话从Web应用程序的Azure的应用程序设置清晰的文本字符串。我是IM pression下,环境变量是用于非配置文件。然而,我想用相同的方法进行的web.config文件
I am currently Following these tutorials, and I am wanting to call the clear text string from Azure's Application Settings for Web Apps. I am under the impression that environmental variables are used for non-config files. However, I am wanting to use the same methodology for web.config files.
<connectionStrings configSource="/config/ConnectionStrings.config">
<add name="DefaultConnection" connectionString="@Environment.GetEnvironmentalVariable('SQLAZURECONNSTR_DefaultConnection')" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings file="config\AppSettingsSecret.config">
<!-- Code Removed for Conciseness-->
<add key="mailAccount" value="@Environment.GetEnvironmentalVariable('APPSETTING_mailAccount')" />
<add key="mailPassword" value="@Environment.GetEnvironmentalVariable('APPSETTING_mailPassword')" />
<!-- Twilio-->
<add key="TwilioSid" value="@Environment.GetEnvironmentalVariable('APPSETTING_TwilioSid')" />
<add key="TwilioToken" value="@Environment.GetEnvironmentalVariable('APPSETTING_TwilioToken')" />
<add key="TwilioFromPhone" value="@Environment.GetEnvironmentalVariable('APPSETTING_TwilioFromPhone')" />
</appSettings>
请注意:我包括configSource =/例子/本地测试
Note: I included the configSource="/example/" for local testing.
推荐答案
在&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
语法%变量%
,然后用<$c$c>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.
这篇关于你怎么把环境变量在web.config中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!