In large projects, there may be a third-party class library configuration such as: LOG4.NET,AOP framework UNITY,WCF, or custom configuration, resulting in the Web. config content too much, difficult to maintain, affecting the config initialization.
At this point we can use ConfigSource to split the Web. config to improve flexibility and legibility.
Separate the appsetting and ConnectionString configurations, as in the following code.
ConfigSource="configs\appsettings.config"configSource=" Configs\connectionstrings.config " />
In the sibling directory:
The Appsetting.config code is as follows:
<appSettings> <add key="IsOpen" value= ""/> <add key= " Android "value=" "/></appsettings>
Connectionstring.config as follows:
<connectionStrings> <add name="defaultconnection"connectionstring="Data source= (LocalDb) \v11.0;initial catalog=aspnet-webapplication1-20140304225906;integrated
SECURITY=SSPI; attachdbfilename=| Datadirectory|\aspnet-webapplication1-20140304225906.mdf"ProviderName="System.Data.SqlClient"/> <add name="reportservertempdbconnectionstring"connectionstring="Data Source=.;i Nitial catalog=reportservertempdb;integrated security=true"ProviderName="System.Data.SqlClient"/> </connectionStrings>
Configsource in Web. config