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 =

namespace DIDAO.Admin
{
/// <summary>
/// testConfig 的摘要说明
/// </summary>
public class testConfig : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
string conCurr = ConfigurationManager.ConnectionStrings["dbconnStr"].ConnectionString;
//如果机器级别有这个name,而应用程序也有这个name,就会报错,需要remove移除机器级别的name 或clear清楚机器级别的所遇配置。
string conMach = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
//子类级别的配置文件 : 必须在子目录级别才能读取
string conChild = ConfigurationManager.ConnectionStrings["child"].ConnectionString; context.Response.Write("应用程序级别的config:"+conCurr+"<br/>");
context.Response.Write("机器级别的config:" + conMach + "<br/>");
context.Response.Write("子级别的config:" + conChild + "<br/>");
} public bool IsReusable
{
get
{
return false;
}
}
}
}

//子目录级别的示例:

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

namespace DIDAO.Admin.testDir
{
/// <summary>
/// testChild 的摘要说明
/// </summary>
public class testChild : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.ContentType = "text/html";
string conCurr = ConfigurationManager.ConnectionStrings["dbconnStr"].ConnectionString;
//如果机器级别有这个name,而应用程序也有这个name,就会报错,需要remove移除机器级别的name 或clear清楚机器级别的所遇配置。
string conMach = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
//子类级别的配置文件 : 必须在子目录级别才能读取
string conChild = ConfigurationManager.ConnectionStrings["child"].ConnectionString; context.Response.Write("应用程序级别的config:" + conCurr + "<br/>");
context.Response.Write("机器级别的config:" + conMach + "<br/>");
context.Response.Write("子级别的config:" + conChild + "<br/>");
} public bool IsReusable
{
get
{
return false;
}
}
}
}

配置文件的继承与覆盖: 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. windows7 安装Apache2时出现failed to open the winNT service manager 提示

    因为电脑实在太慢了,C盘的空间所剩无几,要想再安装大一点的软件的话,可能性很小.加之系统已经好久没有重装过了,于是重新安装windows7旗舰版,系统装好后,免不了一堆软件的重装和开发环境配置,首要的 ...

  2. INSPIRED启示录 读书笔记 - 第18章 重新定义产品说明文档

    理想的产品说明文档 1.产品说明文档应该完整地描述用户体验——不只是用户需求,还包括交互设计和视觉设计.用户需求和用户体验是密不可分的 2.产品说明文档必须准确地描述软件的行为 3.产品说明文档必须以 ...

  3. Cisco学习笔记

    目录 1. 路由 1.1 静态路由 1.2 动态路由 2. 访问控制列表 2.1 标准访问控制列表 2.2 扩展访问控制列表 2.3 命名访问控制列表 3. VLAN 3.1 基础知识 3.2 配置实 ...

  4. idea创建git分支

        此时只是在本地创建好了分支,修改源代码后add,commit将本地分支提交到远程仓库            分支已创建,其它成员此时就可以从git拉分支

  5. springcloud-搭建服务注册中心

    创建服务注册中心 1.创建一个springboot 命名为eureka-server 1)添加Eureka依赖 pom.xml <?xml version="1.0" enc ...

  6. linux基础(8)-文件处理(awk 、sed、grep)

    grep基本用法 格式:grep [选项] [模式] [文件]   选项: -c:只显示有多少行匹配 ,而不具体显示匹配的行 -n:在每一行前面打印该行在文件中的行数 -i:在字符串比较的时候忽略大小 ...

  7. linux基础(1)-yum源配置

    用linux将近一年了,开始学的东西因为没经常用都忘记了,现在将笔记的东西慢慢整理成自己的博客,也算是看着自己进步.有些东西从他人博客笔记学的,有些是从视频学的,有些是自己填坑积累的. 在linux下 ...

  8. sqoop1.4.6 全量导入与增量导入 与使用技巧

    全量导入: sqoop import --connect jdbc:mysql://192.168.0.144:3306/db_blog --username root --password 1234 ...

  9. myeclipse下搭建hadoop2.7.3开发环境

    需要下载的文件:链接:http://pan.baidu.com/s/1i5yRyuh 密码:ms91 一  下载并编译  hadoop-eclipse-plugin-2.7.3.jar 二  将had ...

  10. 【整理】C#文件操作大全(SamWang)

    [整理]C#文件操作大全(SamWang) 文件与文件夹操作主要用到以下几个类: 1.File类: 提供用于创建.复制.删除.移动和打开文件的静态方法,并协助创建 FileStream 对象. msd ...