ConfigSource Property: Dividing configuration files into pieces

If you need to divide the web.config or app.config file into pieces for any reason – imagine you just don’t like a lot of settings of components that you will never need to change – it is even possible in .NET. The only thing you have to find out is how to use “ConfigSource” property of System.Configuration.SectionInformation (MSDN: Contains metadata about an individual section within the configuration hierarchy.) class.

Each configuration section that derives from this class has the ability of getting its configuration settings from a separate “config” file.

In a case that you would like to store your connections strings in a different “config” file, the way you have to follow is shown in the example below.

web.config file:

<?xml version="1.0"?>
  <connectionStrings configSource="ConnectionStrings.config" />
    <!-- settings... -->

ConnectionStrings.config file:

  <clear />
  <add name="SqlServer" connectionString="..." />

You may also like...

2 Responses

  1. Matt says:

    Very good tutorial! I like it

  1. Sun, 18 Jan 2009

    […] your connection strings clearly, please refer to one of my posts describing how to achieve that:…s-into-pieces/ > > Thanks. > All the best, Coskun SUNALI Microsoft MVP […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.