Original article: http://www.codeproject.com/KB/aspnet/Manage_Webconfig.aspx
Introduction
The configsource attribute was firstly introduced in. NET Framework 2.0 to support external configuration files.
After upload website to online server, I need to manage the website setting from web. config, therefore, I save the specified ettings, connectionstrings and all settings are needed to manage in separate XML files, to manage and organize.
This can be done by using configsource attribute, the configsource attribute was firstly introduced in. net Framework 2.0 to support external configuration files. this attribute can be added to any configuration section to specify a external file for that section. using an external configuration source can be useful in your scenarios. for instance, you cocould place a section into an external configsource if you need an easy method to swap settings for the section depending on the environment.
Using the code
First create XML file for eachWeb. configSection like appsettings. XML, connectionstring. XML, and set the file inApp_dataFolder to protect.
Copy the each section fromWeb. configAnd set in XML file as following example: (appsettings. XML)
< ? XML version =" 1.0" Standalone = " Yes" ? > < Appsettings > < Add key = " Enableerrorpage" Value = " False" / > < Add key = " Requiredlogin" Value = " False" / > < Add key = " Publicationsemail" Value = " Email@domain.com" / > < Add key = " Adminfromemail" Value = " Email@domain.com" / > < Add key = " Admintoemail" Value = " Email@domain.com" / > < Add key = " Supportemail" Value = " Email@domain.com" / > < /Appsettings >
InWeb. configChangeAppsettingsTags
<Appsetemediconfigsource ="App_data \ webconfigxml \ appsettings. xml"/>
The configsource attribute must be a relative physical path.
Repeat this for eachWeb. configSection (connectionstrings, SMTP ).
Now you can manage the XML file from secure page by usingGridviewControl to edit and update the values.
Conclusion
The Web. config file is smaller and hence easier to read, and you don't need a complete Web. config file for each environment, and help me to manage the website setting.