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

<o:p> </o:p>

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

<o:p> </o:p>

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.

<o:p> </o:p>

RefreshSection

<o:p> </o:p>

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

<o:p> </o:p>

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):

<o:p> </o:p>

OpenMachineConfiguration

<o:p> </o:p>

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

<o:p> </o:p>

OpenMappedMachineConfiguration

<o:p> </o:p>

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

<o:p> </o:p>

OpenExeConfiguration

<o:p> </o:p>

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

<o:p> </o:p>

OpenMappedExeConfiguration

<o:p> </o:p>

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

 

OpenWebConfiguration

<o:p> </o:p>

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

 

OpenMappedWebConfiguration

<o:p> </o:p>

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值