CloudConfigurationManager 与 WebConfigurationManager?

CloudConfigurationManager vs WebConfigurationManager?(CloudConfigurationManager 与 WebConfigurationManager?)
本文介绍了CloudConfigurationManager 与 WebConfigurationManager?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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?

推荐答案

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:

WebConfigurationManager.AppSettings["MySetting"]

WebConfigurationManager.AppSettings["MySetting"]

对于 ServiceConfiguration.cscfg 文件:

For ServiceConfiguration.cscfg file:

RoleEnvironment.GetConfigurationSettingValue("MySetting")

RoleEnvironment.GetConfigurationSettingValue("MySetting")

我们可以编写下面的语句,它将从所有配置文件(即 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.GetSetting("MySetting")

CloudConfigurationManager.GetSetting("MySetting")

这篇关于CloudConfigurationManager 与 WebConfigurationManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)