David的测试技术空间,收藏好文档和分享我的技术理解。5年的数通产品测试和安全产品测试经验,3年Web产品测试和多年测试管理和测试工具开发经验。目前关注性能分析调优、Jmeter和TestNG+WebDriver+Hamcrest的培训推广。Welcome沟通交流,请留言或者发邮件到daviwang_2004 at soguo.com。

vs.net 2005中的ConfigurationManager

上一篇 / 下一篇  2007-08-23 08:38:33 / 个人分类:旧资料

转贴自:http://www.cnblogs.com/jackyrong/archive/2005/05/06/150067.html
对理解我们目前的产品有用处,贴上
 
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

 

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 theGetSectionmethod.

 

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.


TAG: 与目前工作有关的杂项

 

评分:0

我来说两句

Open Toolbar