Examples of broken-out config files

By | Mar 25, 2018

In the previous post I showed how to how to use the configSource to create multiple broken-out config files to ease maintenance.

Below are more examples of where the configSection can be used.

ConnectionStrings example

<connectionStrings configSource="App_Data\Configuration\Configuration.ConnectionStrings.config"/>
<?xml version="1.0" standalone="yes"?><connectionStrings><add name="Sales"
providerName="System.Data.SqlClient"
connectionString= "server=myserver;database=Products;uid=salesUser;pwd=sellMoreProducts" /><add name="NorthWind"
providerName="System.Data.SqlClient"
connectionString="server=.;database=NorthWind;Integrated Security=SSPI" /></connectionStrings>

System.ServiceModel example

As I mentioned before the configSource attribute can only be found on Sections and not to sectionGroups. That means you have to create a file for each section within the system.serviceModel sectionGroup as in the example below.


<system.serviceModel>
<extensions configSource="App_Data\Configuration\System.ServiceModel.Extensions.config"/>
<services configSource="App_Data\Configuration\System.ServiceModel.Services.config"/>
<behaviors configSource="App_Data\Configuration\System.ServiceModel.Behaviors.config"/>
<bindings configSource="App_Data\Configuration\System.ServiceModel.Bindings.config"/>
<services configSource="App_Data\Configuration\System.ServiceModel.Services.config"/>
</system.serviceModel>

Authorization example

Unfortunately the use of the config Source for the authorization element is not as helpful as what it could have been.

The problem with the authorization element is that it is a child element of system.web section group and to apply authorization to different areas of your website you need to use the location section group. That means at best you can have a authorization file for each location but all you can put in the files are the Allow and Deny elements which does not really reduce the amount of config in the main file.

<location path="Errors">
<system.web>
<authorization configSource="Authorization.Allow.config">
</authorization>
</system.web>
</location>
<location path="Controls">
<system.web>
<authorization configSource="Authorization.Deny.config">
</authorization>
</system.web>
</location>

Leave a Reply

avatar

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

  Subscribe  
Notify of