Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudConfigurationManager vs WebConfigurationManager?

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"];  

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"); 

Although CloudConfigurationManager seems like it's better fitted to cloud use, I never had any issues with WebConfigurationManager.

  • Should I be using CloudConfigurationManager?
  • What are the differences between the two?
  • In what cases CloudConfigurationManager will behave diffrent from
    WebConfigurationManager?
like image 318
Yaron Levi Avatar asked Apr 15 '15 16:04

Yaron Levi


2 Answers

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")

like image 104
Sajad Deyargaroo Avatar answered Sep 20 '22 18:09

Sajad Deyargaroo


CloudConfigurationManager requires Microsoft.WindowsAzure.Configuration assembly, part of Azure SDK or separate NuGet.

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

like image 39
RaSi Avatar answered Sep 21 '22 18:09

RaSi