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 ...
If you want to change web. config files you can use the Azure portal, there is a tool called "App Service Editor" in preview or Kudu that lets you edit any of the files you've deployed.
Configure general settings. In the Azure portal, search for and select App Services, and then select your app. In the app's left menu, select Configuration > General settings. Here, you can configure some common settings for the app.
There are two types of Azure Cloud Services roles. The only difference between the two is how your role is hosted on the VMs: Web role: Automatically deploys and hosts your app through IIS. Worker role: Does not use IIS, and runs your app standalone.
The three roles are important to understand in regard to Azure applications. You can see that the three key roles are the web role, the worker role,and the VM role. These roles are a key components of an Azure application. In upcoming articles, you'll learn how to write applications targeting the Azure platform.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With