C#有三种级别的配置文件:

机器级别      machine.config  在 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config 中

应用程序级别的     web.config    

子级别的      web.config    在子目录中     

她们依次具有继承和覆盖关系:  机器级别 >  应用程序级别 > 子级别

(1)application中可以读取到machine级别的配置信息,子目录中可以读取到application和machine级别的配置信息,所以依次具有继承关系。

(2)同时因为子配置信息 会覆盖父级配置信息,所以需要remove移除以前的配置信息 或者clear父级配置信息。

(3)application级别不能读取子目录的配置信息,因为继承是单方向的。

//application级别的示例:

<connectionStrings>
<remove name="LocalSqlServer"/>
<!--<clear/>-->
<add name="LocalSqlServer" connectionString="hahhahhahah"/>
<add name="dbconnStr" connectionString="Data Source=(DESCRIPTION =

  1. namespace DIDAO.Admin
  2. {
  3. /// <summary>
  4. /// testConfig 的摘要说明
  5. /// </summary>
  6. public class testConfig : IHttpHandler
  7. {
  8.  
  9. public void ProcessRequest(HttpContext context)
  10. {
  11. context.Response.ContentType = "text/html";
  12. string conCurr = ConfigurationManager.ConnectionStrings["dbconnStr"].ConnectionString;
  13. //如果机器级别有这个name,而应用程序也有这个name,就会报错,需要remove移除机器级别的name 或clear清楚机器级别的所遇配置。
  14. string conMach = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
  15. //子类级别的配置文件 : 必须在子目录级别才能读取
  16. string conChild = ConfigurationManager.ConnectionStrings["child"].ConnectionString;
  17.  
  18. context.Response.Write("应用程序级别的config:"+conCurr+"<br/>");
  19. context.Response.Write("机器级别的config:" + conMach + "<br/>");
  20. context.Response.Write("子级别的config:" + conChild + "<br/>");
  21. }
  22.  
  23. public bool IsReusable
  24. {
  25. get
  26. {
  27. return false;
  28. }
  29. }
  30. }
  31. }

//子目录级别的示例:

<connectionStrings>
<add name="child" connectionString="asasasasasasaaas"/>
</connectionStrings>

  1. namespace DIDAO.Admin.testDir
  2. {
  3. /// <summary>
  4. /// testChild 的摘要说明
  5. /// </summary>
  6. public class testChild : IHttpHandler
  7. {
  8.  
  9. public void ProcessRequest(HttpContext context)
  10. {
  11. context.Response.ContentType = "text/plain";
  12. context.Response.ContentType = "text/html";
  13. string conCurr = ConfigurationManager.ConnectionStrings["dbconnStr"].ConnectionString;
  14. //如果机器级别有这个name,而应用程序也有这个name,就会报错,需要remove移除机器级别的name 或clear清楚机器级别的所遇配置。
  15. string conMach = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
  16. //子类级别的配置文件 : 必须在子目录级别才能读取
  17. string conChild = ConfigurationManager.ConnectionStrings["child"].ConnectionString;
  18.  
  19. context.Response.Write("应用程序级别的config:" + conCurr + "<br/>");
  20. context.Response.Write("机器级别的config:" + conMach + "<br/>");
  21. context.Response.Write("子级别的config:" + conChild + "<br/>");
  22. }
  23.  
  24. public bool IsReusable
  25. {
  26. get
  27. {
  28. return false;
  29. }
  30. }
  31. }
  32. }

配置文件的继承与覆盖: Machine.config / Web.config /子目录 Web.config的更多相关文章

  1. 配置子目录Web.config使其消除继承,用虚拟目录创建多个网站的方法

    来源:http://www.wtnzone.com/post/2011/02/20/Set-Web-Config-to-Turn-Inheritance-Off.aspx ASP.NET提供了强大的W ...

  2. 配置子目录Web.config使其消除继承,iis7.0设置路由

    iis7.0设置路由 ,url转向,伪静态 <system.webServer>      <modules runAllManagedModulesForAllRequests=& ...

  3. C# Webservice 解决在运行配置文件中指定的扩展时出现异常。 ---> System.Web.HttpException: 超过了最大请求长度问

    摘自: http://blog.csdn.net/gulijiang2008/article/details/4482993 请在服务器端配置 方法一: 在通过WebService处理大数据量数据时出 ...

  4. 关于Web.config的debug和release.config文件

    使用Web.Config Transformation配置灵活的配置文件 发布Asp.net程序的时候,开发环境和发布环境的Web.Config往往不同,比如connectionstring等.如果常 ...

  5. Web读取指定的config文件的内容

    需求: 什么时候会用到动态改变Web.config内的值? 在Web.config定义了一个全局设置值A,因为程序运行中满足了某个条件,要将A的值改变 Web.config中定义: <appSe ...

  6. peomethues 参数设置 监控网站 /usr/local/prometheus-2.13.0.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.13.0.linux-amd64/prometheus.yml --web.listen-address=:9999 --web.enable-lifecycle

    probe_http_status_code{instance="xxxx",job="web_status"} probe_http_status_code{ ...

  7. web php wrong nginx config

    web php wrong nginx config 目录 web php wrong nginx config 题目描述 解题过程 信息收集 robots.txt hint.php Hack.php ...

  8. Web.config Transformation Syntax for Web Application Project Deployment

    Web.config Transformation Syntax for Web Application Project Deployment Other Versions   Updated: Ma ...

  9. App.config使用ASP.NET Web Project的Transformation

    1.创建对应configuration的App.config文件,比如:App.Debug.config.App.Release.config. 2.编辑项目文件,将App.*.config文件的Bu ...

随机推荐

  1. samtools使用过程中出现的问题

    1.EOP marker is absent 在使用samtools index时出现 EOF是指the end of file,即samtools认为你的bam文件是不完整的. 如果把view参数的 ...

  2. awk的逻辑运算符

    运算符 描述 赋值运算符 = += -= *= /= %= ^= **= 赋值语句 逻辑运算符 || 逻辑或 && 逻辑与 正则运算符 ~ ~! 匹配正则表达式和不匹配正则表达式 关系 ...

  3. INSPIRED启示录 读书笔记 - 第19章 用户体验设计与实现

    先定义用户体验再动手开发 在软件开发过程中,有很多工作可以同时进行.比如,需求调研和产品设计(用户体验设计).开发与测试 尽管如此,用户体验设计和软件开发就不能同时进行,原因有五点 1.与软件开发团队 ...

  4. RSA签名 python PHP demo 例子

    python RSA+MD5签名demo: #!/usr/bin/env python2.7 #coding:utf-8 import base64 from Crypto.PublicKey imp ...

  5. 【转载】丑数humble numbers

    转载地址:http://blog.csdn.net/qwerty_xk/article/details/12749961 题:只有2 3 5 这三个因子的数,求第1500个   设1为第一个丑数,求第 ...

  6. 一言(ヒトコト)Hitokoto API

    『想要成为无论多么悲伤的时候,也能够漂亮微笑的人吧.』 Hitokoto API 更新:2014.02.22 问题/反馈:api # hitokoto.us 数据获取:[ 数据获取 ] 调用举例:[  ...

  7. 【P3572】little bird(单调队列+DP)

    一眼看上去这个题就要DP,可是应该怎么DP呢,我们发现,数据范围最多支持O(NlogN),但是这种DP貌似不怎么有,所以应该是O(N)算法,自然想到单调队列优化DP. 然后我们先考虑如果不用单调队列应 ...

  8. streambase service 变为 window service启动

    1.配置出.sbdeploy文件 2.安装streambase服务 streambase command line :--install-service 即可安装对应的的window service ...

  9. HDU 4000 Fruit Ninja (树状数组+反向思维)

    题意:给你一串数且每个数都不同,问你(x,y,z)出现 x<z<y 的总次数 首先我们直接想的话不能使用O(n*log2 n)解决,所以可以正难则反 可以求得x<(y,z)的值,减去 ...

  10. 微信小程序申请。很蛋疼的流程。

    微信小程序申请. 营业执照,食品许可证,身份证正面,身份证反面. 1.先要申请服务号. 需要一个QQ邮箱,申请服务号. 填写各种信息,营业执照信息. 法人信息. 管理员用自己人的.方便开发操作. 申请 ...