原文链接

今天在写程序时偶然发现有的示例代码中是用WebConfigurationManager获取web.config中的配置信息的,因为之前一直都是用的ConfigurationManager,所以简单的深究了一下,并做个小小的总结。

MSDN的说明:

使用 WebConfigurationManager 可以访问计算机和应用程序信息。

使用 WebConfigurationManager 是处理与 Web 应用程序相关的配置文件的首选方法。对于客户端应用程序,请使用 ConfigurationManager

不知道这里是否可以理解为:

1. 对于web应用程序而言,建议优先使用WebConfigurationManager ;但该方法不适用于客户端应用程序比如winform,WPF程序。

2. ConfigurationManager ,即适用于web应用程序,也适用于客户端应用程序,但对于客户端应用程序来说更好。

  //对于客户端应用程序,请使用 ConfigurationManager。
protected static string connectionString = ConfigurationManager.ConnectionStrings["ConnStr"].ToString(); protected static string appconfigString = ConfigurationManager.AppSettings[""].ToString(); //使用 WebConfigurationManager 是处理与 Web 应用程序相关的配置文件的首选方法。
protected static string webconnectionString = WebConfigurationManager.ConnectionStrings[""].ToString(); protected static string webappconfigString = WebConfigurationManager.AppSettings[""].ToString(); //Web.config中的配置节点: //ConnectionStrings
//<connectionStrings>
// <add name="ConnStr" connectionString="Data Source=.;user ID=sa;Pwd=123456;Database=database;"/>
//</connectionStrings> //AppSettings
//<appSettings>
// <add key="" value=""/>
//</appSettings> //写在 <appSettings >中用System.Configuration.ConfigurationManager.AppSettings["name"]检索值。
//写在 <ConnectionStrings>中用System.Configuration.ConfigurationManager.ConnectionStrings["name"]检索值。 //注意:
//System.Web.Configuration 默认没有在程序中添加引用,所以直接using无法using出来。
复制代码

  

最新文章

  1. Oracle学习笔记十三 触发器
  2. LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
  3. [Cocos2d-x For WP8]DrawPrimitives画图
  4. 【mysql的紧急应用】
  5. CSS中 opacity的设置影响了index(层数)的改变
  6. 前端MVC框架对比
  7. HDU 4612 Warm up(手动扩栈,求树上哪两个点的距离最远)
  8. HDU 4957 Poor Mitsui
  9. Spring Session - Spring Boot
  10. java map集合的知识
  11. 使用Xilinx UART-LITE IP实现串口--逻辑代码实现
  12. ruby-操作mysql
  13. 浏览器内核、渲染引擎、JS引擎简介
  14. python基础技巧综合训练题1
  15. 用Hadoop构建电影推荐系统
  16. 怎么把&lt;li&gt;标签里的内容付给文本框
  17. Linux-数据库1
  18. 用newInstance与用new是区别的
  19. Java发送短信
  20. 斯坦福大学Andrew Ng - 机器学习笔记(8) -- 推荐系统 &amp; 大规模机器学习 &amp; 图片文字识别

热门文章

  1. 单点登录cas常见问题(二) - 子系统是否会频繁訪问cas中心?
  2. MapReduce输入输出类型、格式及实例
  3. Atitit.软件仪表盘(7)--温度监測子系统--电脑重要部件温度与监控and警报
  4. window.location.hashs属性介绍
  5. 关于disable和readonly
  6. RGB中的颜色的设置
  7. Android中View窗口getWidth和getMeasuredWidth的差别
  8. 32位与4G内存限制
  9. Linux服务基础命令
  10. java8--IO工具类(java疯狂讲义3复习笔记)