转:Manage Web.config from XML File by using configSource attribute ASP.Net 2.0
2010-05-01 15:51
706 查看
original article: http://www.codeproject.com/KB/aspnet/Manage_Webconfig.aspx
After upload website to online server, I need to manage the Website setting from Web.Config, therefore, I save the appSettings, connectionStrings and all settings are needed to manage in Separate XML files, to ease 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 an external file for that section. Using an external configuration source can be useful in many scenarios. For instance, you could place a section into an external configSource if you need an easy method to swap settings for the section depending on the environment.
Copy the each section from
In the
The configSource attribute must be a relative physical path.
Repeat this for each
Now you can manage the XML file from secure page by using
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 appSettings, connectionStrings and all settings are needed to manage in Separate XML files, to ease 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 an external file for that section. Using an external configuration source can be useful in many scenarios. For instance, you could 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 in
App_DataFolder to protect.
Copy the each section from
web.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>
In the
Web.configchange the
appSettingstags to
<appSettings configSource="App_Data\WebConfigXML\appSettings.xml"/>
The configSource attribute must be a relative physical path.
Repeat this for each
web.configSection (connectionStrings, smtp,�).
Now you can manage the XML file from secure page by using
Gridviewcontrol 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.相关文章推荐
- Read ConnectionString from web.config in ASP.NET 2.0
- Using connection strings from web.config in ASP.NET v2.0
- HOW TO: Upload a File to a Web Server in ASP.NET by Using Visual Basic .NET
- asp.net 2.0中加密web.config
- asp.net 2.0 中使用web.config存储数据库连接字符串
- asp.net 2.0小tips:在web.config里设置用户定义控件
- asp.net 2.0的web.config变化
- ASP.NET 2.0加密Web.config 配置文件
- 在Web.Config文件中使用configSource,避免动态修改web.config导致asp.net重启
- 在asp.net 2.0中的web.config文件中调用外部文件
- WCF项目问题2-无法激活服务,因为它需要 ASP.NET 兼容性。没有未此应用程序启用 ASP.NET 兼容性。请在 web.config 中启用 ASP.NET 兼容性,或将 AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode 属性设置为 Required 以外的值。
- 在asp.net 2.0中的web.config文件中调用外部文件
- asp.net 对 xml webconfig的操作
- ASP.NET 2.0 web.config数据库连接设置与读取
- ASP.NET 2.0加密Web.config 配置文件
- Web Parts: From SharePoint to ASP.NET 2.0
- asp.net 2.0中新增的web.config的默认namespace功能 (转)
- ASP.NET 2.0加密Web.config 配置文件
- ASP.NET 2.0 中加密Web.config中的项目
- ASP.NET 2.0加密Web.config 配置文件