Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure web/worker role read configuration settings

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

like image 781
user2818430 Avatar asked Oct 28 '13 19:10

user2818430


People also ask

How do I change my Azure web config?

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.

How are configurations in Azure App Service configured?

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.

What is the difference between web role and Worker role in Azure?

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.

What is role discuss the types of roles used in Windows Azure platform?

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.


Video Answer


1 Answers

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.

like image 94
Gaurav Mantri Avatar answered Oct 19 '22 16:10

Gaurav Mantri