How to use the configSource.

By | Mar 25, 2018

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.

  1. I created a sub folder for my configuration files under App_Data and created a config file called Configuration.Appsettings.config.
  2. 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>
  3. 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.
    <appSettings configSource="App_Data\Configuration\Configuration.Appsettings.config"/>
    

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.

See more Examples here relating to connectionstrings, system.servicemodel and authorization here.

0 0 vote
Article Rating
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments