Reading configuration entries using System.Configuration.ConfigurationManager class in a Windows Azure Application

With Windows Azure application you can use ServiceConfiguration.cscfg to include any item-value pair and then in your role code you can read these settings directly however if you would want to read configuration entries using System.Configuration.ConfigurationManager class in an Azure application then you would need to use little different method to get it done. The potential reasons for different method are as below:


With Web Role:

  • In a web role OnStart() function runs within WaIISHost.exe which does not have any association with web.config and the web.config you had is part of w3wp.exe process which is running separately.


With Worker Role:

  • In worker role OnStart() function runs WaWorkerHost.exe and I believe with worker role you would not have a web.config associated with it.


So whenever you would need to use configuration entries in your OnStart() function using System.Configuration.ConfigurationManager class you would need to create an app.config file in your Windows Azure project and included all of your configuration related data in it.


Step 1: Adding app.config to your Windows Azure application:

Step 2: Adding Configuraiton items into App.config

<?xml version="1.0"?>
<supportedRuntime version="v2.0.50727"/>
<add key="ConfigurationItem" value="ThisIsCongiruationItem" />

Step 3: Reading Configuration related data in your Web Role OnStart() function as below:

 public class WebRole : RoleEntryPoint
public override bool OnStart()
// For information on handling configuration changes
// see the MSDN topic at
string myConfiguration = System.Configuration.ConfigurationManager.AppSettings.Get("ConfigurationItem");
return base.OnStart();

Testing the code:

While running the code in compute Emulator you can verify the value is read correctly as below:

If you don’t have app.config and reading configuration data using Configuration Manager class you will get results as below:

Comments (1)

  1. Nice info. I thought only service configuration can be used for settings but now I can also use app.config, very good idea. Thanks for nice post.

Skip to main content