The size of configuration files often creates the desire to split it into multiple smaller more manageable parts. To achieve this one can break the file into smaller more manageable parts by using configSource attribute.
How to use the configSource attribute?
Below I will show how to to split the appsettings from the web.config into a separate file.
- I created a sub folder for my configuration files under App_Data and created a config file called Configuration.Appsettings.config.
- Copy the appsettings section to the new file and add the xml deceleration must be added to the first line of the new file;
<?xml version="1.0" standalone="yes"?>
The complete file should look something like this.
<?xml version="1.0" standalone="yes"?> <appSettings> <add key="Product" value="STS" /> <add key="TokenLifeTimeHours" value="8" /> <add key="MaxTokenLifeTimeHours" value="10" /> <add key="ResetLinkLifeTimeHours" value="24" /> </appSettings>
- Return to the main config file and alter the original appsettings section. Use the configSource to instruct the config where the new file can be found.
Something that must be understood is that the attribute can only be found on sections and not on section groups, this does limit its ability somewhat.