【转载】WebConfigurationManager和ConfigurationManager
今天在写程序时偶然发现有的示例代码中是用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出来。
复制代码

【转载】WebConfigurationManager和ConfigurationManager的更多相关文章
- 配置文件的读取添加webconfig
webconfig.xml的配置文件内容挺丰富的,在这篇文章里笔者只对AppSettings这个节点进行配置文件读取和添加 public class ConfigurationRef { /// &l ...
- ASP.NET Web.config文件的配置(Configuration API)
本次我们讨论主要聚焦在以下Web.config配置文件的设置值的读取. 1.<connectionString />连接字符串的读取. 2.<appSettings />应用程 ...
- ASP.NET系列:自定义配置节点的复用
appSettings太简单,为每个程序自定义配置节点太复杂,因此要解决app.config&web.config自定义配置的复用问题. 1.读取不依赖SectionName,根节点可以定义为 ...
- System.ConfigurationManager类用于对配置文件的读取
http://blog.csdn.net/ligenyingsr/article/details/54095986 System.ConfigurationManager类用于对配置文件的读取.其具有 ...
- ahjesus 前端缓存原理 转载
LAMP缓存图 从图中我们可以看到网站缓存主要分为五部分 服务器缓存:主要是基于web反向代理的静态服务器nginx和squid,还有apache2的mod_proxy和mod_cache模 浏览器缓 ...
- ASP.NET Web Api 使用CacheCow和ETag缓存资源(转载)
转载地址:http://www.cnblogs.com/fzrain/p/3618887.html 前言 本文将使用一个开源框架CacheCow来实现针对Http请求资源缓存,本文主要介绍服务器端的缓 ...
- [转载]单元测试之道(使用NUnit)
首先来看下面几个场景你是否熟悉 1.你正在开发一个系统,你不断地编码-编译-调试-编码-编译-调试……终于,你负责的功能模块从上到下全部完成且编译通过!你长出一口气,怀着激动而又忐忑的心情点击界面上的 ...
- [转载]App.Config详解及读写操作
App.Config详解 应用程序配置文件是标准的 XML 文件,XML 标记和属性是区分大小写的.它是可以按需要更改的,开发人员可以使用配置文件来更改设置,而不必重编译应用程序.配置文件的根节点是c ...
- 用ConfigurationManager读取和修改配置文件
为了方便有时我们会把一些简单的配置的信息放入web.config文件里. 放到appSettings添加key value等信息. ConfigurationManager.AppSettings ...
随机推荐
- poj2481 Cows
Description Farmer John's cows have discovered that the clover growing along the ridge of the hill ( ...
- C#如何引用定义好的dll文件
1 添加引用,找到dll文件 2 引用类的名称空间,生成类的实例,调用类的方法,测试OK.
- PHP记录商品历史纪录
/* 记录浏览历史 */ if (!empty($_COOKIE['history'])) { if(stripos($_COOKIE['history'].',',$goods_id.',')=== ...
- 【Jquery】jQuery获取URL參数的两种方法
jQuery获取URL參数的关键是获取到URL,然后对URL进行过滤处理,取出參数. location.href是取得URL.location.search是取得URL"?"之后的 ...
- How to: Use Submix Voices
How to: Use Submix Voices:https://msdn.microsoft.com/en-us/library/windows/desktop/ee415794(v=vs.85) ...
- createElement与innerHtml性能比較
js中.动态加入html的方法大致就是两种,一种是document.createElement等方法创建,然后使用Element.appendChild加入,或者是使用Element.innerHTM ...
- xcode10的那些事
前言 这里主要介绍一下Xcode10 版本主要更新的内容.随着iOS12的发布,Xcode10已经可以从Mac App Store下载.Xcode10包含了iOS12.watchOS 5.macOS1 ...
- P1439 排列LCS问题
P1439 排列LCS问题 56通过 220提交 题目提供者yeszy 标签二分动态规划 难度普及+/提高 提交该题 讨论 题解 记录 最新讨论 暂时没有讨论 题目描述 给出1-n的两个排列P1和P2 ...
- WinPE:创建 USB 可引导驱动器
https://msdn.microsoft.com/zh-cn/library/windows/hardware/dn938386(v=vs.85).aspx
- 定时任务 bash 对远程数据库 备份 读写
1g表 每行都有可能被更新,故全表备份 检测备份是否在进行 [root@hadoop1 ~]# netstat --numeric-ports | grep 3306tcp 0 ...