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.
<?xml version="1.0"?> <configuration> <connectionStrings configSource="ConnectionStrings.config" /> <system.web> <!-- settings... --> </system.web> </configuration>
<connectionStrings> <clear /> <add name="SqlServer" connectionString="..." /> </connectionStrings>