Use configSource attribute to manage Web.Config sections in ASP.Net 2.0

Different Sections in Web.Config can be managed by using external XML files, like Connection strings, Appsettings .....

Create a XML file with the respective settings and put that file in App_Data folder to protect

<?xml version="1.0" standalone="yes"?>
<connectionstrings>
<!-- Connection String for SQL Server 2005 Express -->
<add name="SiteSqlServer" connectionstring="Your Connection" providername="System.Data.SqlClient" />
<!-- Connection String for SQL Server 2000/2005
<add name="SiteSqlServer" connectionstring="Your Connection" providername="System.Data.SqlClient" /> -->
</connectionstrings>

Save the file in App_Data folder you need to change the Settings in Web.Config

<connectionstrings configsource="App_Data\yourFileName.xml" />

You can manipulate the values by simply changing the respective XML files. No need to change the Web.Config any more.





Comments

Herber said…
Just a minor comment. Using xml as extension for your configuration file is not a good idea, because most of the webservers allow the access to this files. It's better if you use .config extension.

Popular posts from this blog

Rewriting the DotNetNuke Url Rewriter Module

DevOps - Key Concepts - Roles & Responsibilities - Tools & Technologies

Restrict Web Page access based on MAC / IP