CloudConfigurationManager vs WebConfigurationManager?

落花浮王杯 提交于 2019-12-01 02:44:27

CloudConfigurationManager enables us to read configuration file regardless of the environment we are in.

So instead of writing environment specific code statements e.g., for web.config file:

WebConfigurationManager.AppSettings["MySetting"]

For ServiceConfiguration.cscfg file:

RoleEnvironment.GetConfigurationSettingValue("MySetting")

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 requires Microsoft.WindowsAzure.Configuration assembly, part of Azure SDK or separate NuGet.

WebConfigurationManager requires System.Web.Configuration assembly, part of .NET Framework.

WebConfigurationManager and CloudConfigurationManager manage different configuration files.

WebConfigurationManager is for managing website's web.config file(s) and it's appsettings and connections strings

CloudConfigurationManager is for managing .cscfg files (for cloud services). His benefit is that you can manage configurations and connections from the azure portal directly.

I think you're better off using WebConfigurationManager. With it, you have access to ConnectionStrings as well as AppSettings. Both sets of settings you can update via the Azure Portal. They can then further be used in other Azure facilities/services, such as when configuring website backup. Check this out for more information: https://azure.microsoft.com/en-us/blog/windows-azure-web-sites-how-application-strings-and-connection-strings-work/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!