Yar*_*evi 13 c# azure azure-web-sites
在Azure网站中,我总是使用以下代码从配置的应用程序设置中获取一些值:
string property = WebConfigurationManager.AppSettings["property"];
Run Code Online (Sandbox Code Playgroud)
就在几天前,我对CloudConfigurationManager进行了测试,有了它,我可以得到这样的属性:
string property = CloudConfigurationManager.GetSetting("property");
Run Code Online (Sandbox Code Playgroud)
虽然CloudConfigurationManager似乎更适合云使用,但我从来没有遇到任何WebConfigurationManager问题.
Saj*_*roo 16
无论我们所处的环境如何,CloudConfigurationManager使我们能够读取配置文件.
因此,不要编写特定于环境的代码语句,例如,对于web.config文件:
WebConfigurationManager.AppSettings [ "MySetting"]
对于ServiceConfiguration.cscfg文件:
RoleEnvironment.GetConfigurationSettingValue( "MySetting")
我们可以编写下面的语句,它将读取所有配置文件中的值,即app.config,web.config和ServiceConfiguration.cscfg.
CloudConfigurationManager.GetSetting( "MySetting")
| 归档时间: |
|
| 查看次数: |
8392 次 |
| 最近记录: |