Question

What is the best way/recommended way to read settings from a worker/web role?

Is it:

CloudConfigurationManager.GetSetting("ConnectionString") (this I'm using)

or

RoleEnvironment.GetConfigurationSettingValue("ConnectionString")

Although both work fine ...

enter image description here

Was it helpful?

Solution

From the documentation for CloudConfigurationManager.GetSetting:

The GetSetting method reads the configuration setting value from the appropriate configuration store. If the application is running as a .NET Web application, the GetSetting method will return the setting value from the Web.config or app.config file. If the application is running in Windows Azure Cloud Service or in a Windows Azure Website, the GetSetting will return the setting value from the ServiceConfiguration.cscfg.

From above, it is clear that the function CloudConfigurationManager.GetSetting reads either from service configuration (ServiceConfiguration.cscfg) file or application configuration file (App.config/Web.config) depending on where the application is running.

RoleEnvironment.GetConfigurationSettingValue will only read from the service configuration file.

If your application component is used in both cloud and non-cloud applications, use CloudConfigurationManager.GetSetting so that you don't have to make any changes in the code. If your component would run only in the cloud, then I guess you could use either one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top