TechBubbles Microsoft Technology BLOG

Working with Configuration files


Configuration files are central place to configure your web or windows applications. The web.config file is used for configuring the web applications and app.config for windows applications.

The ASP.NET Application comes with web.config file with default configuration sections and you can easily manage them at the intialstage of the project development. As soon as your project grows mature, web.config file turns out to be a huge file.

The configuration files can be different from development environment to production environment.

Example: Connection strings, Application settings, logging and compilation settings are differed from development to production environment.

Maintaining multiple configuration files is pain to manage, For this .NET configuration system has a feature that each configuration section can define an attribute named “configSource”  to define an alternative location from where the configuration file has to be loaded.

Example: In web.config file locate the connectionStrings section and add a new attribute name configSource and give the value as “MyConnectionStrings.config”.

   1: <connectionStrings configSource="MyConnectionStrings.config"/>

Add a new file called “MyConnectionStrings.config” to the same directory where web.config lives and define its contents as follows:

   1: <?xml version="1.0"?>

   2: <connectionstrings>

   3:     <add name="MyDataBase" connectionstring=” ”/> 

   4: <connectionstrings>

Key points:

  • External configuration file must contain the section name as the root element.
  • If you use configSource you must not define any other attribute or child element for the respective section in the web.config file.
  • It is useful if you move all your configuration files to subfolder to keep root directory clean.    

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

1 Comment

TechBubbles Microsoft Technology BLOG

Follow me


Tag Cloud