vs.net 2005中的ConfigurationManager

vs.net 2005中的ConfigurationManager,代替了原来的configurationsettings。用法大概如下,详细的看MSDN
读取配置:
ConfigurationManager.AppSettings["MyKey"]

读取数据库的配置(这个估计大家最经常用了)
 在web.config中
<connectionStrings>

  <add name="AppConnectionString1" connectionString="server=localhost;database=northwind;uid=sa;password=xxxx;"/>
 </connectionStrings>

在程序中如下读取:
  SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString);

GETSECTION方法:
 ConfigurationManager.GetSection("mySection")
其他的方法大概描述摘录如下:

GetWebAppSection

<?xml:namespace prefix = o />

 

With the GetWebAppSection you can get the specified section from the web applications configuration file.

 

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.

 

RefreshSection

 

RefreshSection will refresh the specified section so next time its requested, it will be re-read from disk.

 

With the following method, you will have the ability to programmatically change the settings within the configuration files. Those methods will return a Configuration class (The Configuration class has properties to get sections from the configuration file you want to edit, and by using the Save or SaveAs method, you can save the settings):

 

OpenMachineConfiguration

 

With the OpenMachineConfiguration, you configure the machine.config file.

 

OpenMappedMachineConfiguration

 

With the OpenMappedMachineConfiguration, you can open a specified configuration file.

 

OpenExeConfiguration

 

With the OpenExeConfiguration, you can open the client’s configuration file.

 

OpenMappedExeConfiguration

 

With the OpenMappedExeConfiguration, you can open the specified client configuration.

 

OpenWebConfiguration

 

With the OpenWebConfiguration, you can open the web applications configuration file.

 

OpenMappedWebConfiguration

 

With the OpenMappedWebConfiguration, you can open a specified web configuration file.

posted on 2005-05-06 18:11 jackyrong的世界 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/jackyrong/archive/2005/05/06/150067.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值