Tech Dreams

Windows Azure: Read settings from web.config instead of service configuration file if the app is running on non-cloud environment

Traditional web applications maintain their configuration settings in web.config files, where as Windows Azure based applications should have configurable entities into Service Configuration files. What if the application needs to run on Azure as well as traditional environments? Where do you store the configurable entities and how do you access them depending on the environment?

The solution for this problem is to maintain the configurable entities in both web.config as well as Service Configuration files and read from appropriate source depending on the environment in which the application is deployed.

With the help of RoleEnvironment.IsAvailable property we can detect whether the application is running in a Windows Azure environment or not and the following code snippet lets you read the settings from appropriate source


By making use of simple techniques like this developer can write code that runs on multiple environments without much changes.

Happy coding!