WebConfigurationManager相关

In Beta 2 there are now two classes, ConfigurationManager and the WebConfigurationManager.The ConfigurationManager will not longer have methods for getting the web applications configuration file. Instead you shoud use the WebConfigurationFile.If you want to update or add sections to the app.config,you should use the ConfigurationManager class.
在测试版2.0中有两个类:ConfigurationManager和 WebConfigurationManager.ConfigurationManager不再是从网页配置文件获取设置的方法,替代它的是使用 WebConfigurationManager.如果你想更新或者是添加节到文件app.config,你须使用 ConfigurationManager类。

The following is an example of how you can add an appSettings key to the web.config and also how to update an existing key:
接下来的一个例子是如何添加程序设置键值到web.config与如何更新存在的键值:
Configuration config=WebConfigurationManager.OpenWebConfiguration("~");
if(config.AppSettings.Settings["MyAppKey"]==null)
  config.AppSettings.Settings.Add("MyAppKey","Hello!");
else
  config.AppSettings.Settings["MyAppKey"].Value="Hello2!";
config.Save();

The WebConfigurationManager class has the following properties and methods:
WebConfigurationManager 类有以下属性和方法:

AppSettings
Gets a NameValueCollection class that has the values added to the <appSettings> section.
得到NameValueCollection 类以便有个值添加到<appSettings>节中。


ConnectionStrings
Gets a ConnectionStringSettingsCollection class that will have the connections strings added to the <connectionString> section.
得到个ConnectionStringSettingsCollection类,类中将有个连接字符串属性,以便添加到<connectionString>节中。


GetSection
With the GetSection you can get a specific section from the configuration file.
在GetSection下你能从设置文件中得到个指定的节。


GetWebApplicationSection
With the GetWebApplicationSection you can get the specified section from the web applications configuration file.
在GetWebApplicationSection下你能从网页设置文件中得到个指定的节。


Note:This method retrieves the specified configuration section from the configuration file located at the root folder of your Web application.If you want to retrieve the configuration section from the current Web application directory use the GetSection method.
注:这个方法返回定位在你网页程序root 文件中配置文件的配置节。如果你想返回当前网页程序目录下的配置节,可以使用GetSection方法。


OpenMachineConfiguration
With the OpenMachineConfiguration,you configure the machine.config file.
使用OpenMachineConfiguration,你可以配置machine.config文件。


OpenMappedMachineConfiguration
With the OpenMappedMachineConfiguration,you can open a specifed configuration file.
使用OpenMappedMachineConfiguration,你能打开个指定的配置文件。


OpenWebConfiguration
With the OpenWebConfiguration,you can open the web applications configuration file.
使用OpenWebConfiguration,你可以打开网页程序配置文件。


OpenMappedWebConfiguration
With the OpenMappedWebConfiguration,you can open a specifed web configuration file.
使用OpenmappedWebConfiguration,你可以打开指定的网页配置文件。

来源: http://www.cnblogs.com/linhengboy/archive/2005/02/25/109384.html
英文原文: http://fredrik.nsquared2.com

根据msdn的解释,对于   web   应用程序配置,建议使用   system.web.configuration.webconfigurationmanager   类,而不要使用   system.configuration.configurationmanager   类

附:
ConfigurationManager不再是从网页配置文件获取设置的方法,替代它的是使用WebConfigurationManager.如果你想更新或者是添加节到文件app.config,你须使用ConfigurationManager类。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值