问题描述
在Azure网站中,我始终使用以下代码从配置的应用程序设置中获取一些值:
In an Azure Websites I was always using the following code to fetch some values from the config's app settings:
string property = WebConfigurationManager.AppSettings["property"];
就在几天前,我对CloudConfigurationManager进行了设置,并使用它可以像下面这样获得属性:
Just a couple of days ago I stublemd upon CloudConfigurationManager, and with it I can get the property like so:
string property = CloudConfigurationManager.GetSetting("property");
尽管CloudConfigurationManager似乎更适合云使用,但WebConfigurationManager从未出现任何问题.
Although CloudConfigurationManager seems like it's better fitted to cloud use, I never had any issues with WebConfigurationManager.
- 我应该使用CloudConfigurationManager吗?
- 两者之间有什么区别?
- 在什么情况下,CloudConfigurationManager的行为将不同于
WebConfigurationManager?
- Should I be using CloudConfigurationManager?
- What are the differences between the two?
- In what cases CloudConfigurationManager will behave diffrent from
WebConfigurationManager?
推荐答案
CloudConfigurationManager 使我们能够读取配置文件,而不管环境如何.
CloudConfigurationManager enables us to read configuration file regardless of the environment we are in.
因此,与其编写针对环境的代码语句(例如,针对web.config文件):
So instead of writing environment specific code statements e.g., for web.config file:
对于ServiceConfiguration.cscfg文件:
For ServiceConfiguration.cscfg file:
我们可以编写以下语句,该语句将从所有配置文件(即app.config,web.config和ServiceConfiguration.cscfg)中读取值.
We can write the below statement, which will read values from all the configuration files i.e., app.config, web.config and ServiceConfiguration.cscfg.
这篇关于CloudConfigurationManager与WebConfigurationManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!