Dividing web.config into multiple files in asp.net
For this kind of situation this will be a best solution. We can divide particular section of web.config into the multiple files. For example we could have separate ConnectionStrings.config file for connection strings and AppSettings.config file for app settings file.
Most of people does not know that there is attribute called ‘configSource’ where we can define the path of external config file and it will load that section from that external file. Just like below.
<configuration>
<appSettings configSource="AppSettings.config"/>
<connectionStrings configSource="ConnectionStrings.config"/>
</configuration>
And you could have your ConnectionStrings.config file like following.
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-WebApplication1-20120523114732;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Same way you have another AppSettings.Config file like following.
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms" />
</appSettings>
That's it. Hope you like this post. Stay tuned for more!!