Managing Configuration Data Programmatically in ASP.NET 2.0
2008-05-14 10:38
471 查看
链接:http://aspalliance.com/1637_Managing_Configuration_Data_Programmatically_in_ASPNET_20.all
Listing 1
The following method can be used to update a specific key - value pair in the web.config file.
Listing 2
The following method can be used to delete a specific key in the web.config file.
Listing 3
Listing 1
Configuration configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings"); if (appSettingsSection != null) { foreach (string key in appSettingsSection.Settings.AllKeys) { Response.Write(key); } }
The following method can be used to update a specific key - value pair in the web.config file.
Listing 2
public void Update(string key, string value) { Configuration configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings"); if (appSettingsSection != null) { appSettingsSection.Settings[key].Value = value; config.Save(); } }
The following method can be used to delete a specific key in the web.config file.
Listing 3
public void Delete(string key) { Configuration configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings"); if (appSettingsSection != null) { appSettingsSection.Settings.Remove(key); config.Save(); } }
相关文章推荐
- Simplified and Extended Data Binding Syntax in ASP.NET 2.0 -- Cont'd
- 开始正式的看 Working with Data in ASP.NET 2.0
- Display Hierarchical Data with TreeView in ASP.NET 2.0
- Working with Data in ASP.NET 2.0 :: Master Pages and Site Navigation
- A book Working with Data in ASP.NET 2.0 by Scott Mitchell
- Working with Data in ASP.NET 2.0 :: Using TemplateFields in the GridView Control
- Encrypting Configuration Information in ASP.NET 2.0 Applications
- Encrypt Configuration Sections in ASP.NET 2.0 Using DPAPI
- ASP.NET MVC 2.0 in Vs2010 :使用C# 4.0中使用动态类型来传递ViewData
- ASP.NET MVC 2.0 in Vs2010 :使用C# 4.0中使用动态类型来传递ViewData
- How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA
- Simplified and Extended Data Binding Syntax in ASP.NET 2.0
- 捆绑语法详解 Simplified and Extended Data Binding Syntax in ASP.NET 2.0
- [转载]Encrypting Configuration Information in ASP.NET 2.0 Applications
- Simplified and Extended Data Binding Syntax in ASP.NET 2.0(part1)
- ASP.NET MVC 2.0 in Vs2010 :使用C# 4.0中使用动态类型来传递ViewData
- [翻译]Accessing and Updating Data in ASP.NET 2.0: Examining the Data Source Control's Events
- How to Pop Open an image window that resizes to fit the image in ASP.net 1.x and 2.0 Beta 1
- Convert a DataReader to DataTable in ASP.NET
- Pro ASP.NET 2.0 E-Commerce in C# 2005