User Id :    Password :      New Member   Forgot Password  
 
Dividing web.config into multiple files in asp.net
Description When you are having different people working on one project remotely you will get some problem with web.config, as everybody was having different version of web.config. So at that time once you check in your web.config with your latest changes the other people have to get latest that web.config and made some specific changes as per their local environment. Most of people who have worked things from remotely has faced that problem. I think most common example would be connection string and app settings changes.   No. of Views     1491
  Rating     0
Author Jalpesh Vadgama   Posted On     08 Jul 2012
Tags ASP.NET,ASP.NET-MVC,ASP.NET : How To,ASP.NET 4.0    

Sample Code   Download Code


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!!

 

 

About Author

About Author I am jalpesh vadgama an Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 5 years of experience in .NET Technology.Please feel free to contact me for any queries via posting comments on my blog I will try to reply as early as possible. Please also visit my blog at http://jalpesh.blogspot.com/ Jalpesh Vadgama
No Photo
 
Country India
Company N/A
Home Page http://jalpesh.blogspot.com/

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

   
Write your comment here.
Comment
Verification Code