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. mongodb count 导致不正确的数量(mongodb count 一个坑)

    在mongodb 集群中,if  存在orphaned documents 和chunk migration, count查询可能会导致一个不正确的查询结果,例如我就是踩的这个坑,先不说话,看结果: ...

  2. MVC6 OWin Microsoft Identity 自定义验证

    1. Startup.cs中修改默认的验证设置 //app.UseIdentity(); app.UseCookieAuthentication(options => { //options.A ...

  3. poj 3414 Pots【bfs+回溯路径 正向输出】

    题目地址:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  4. cuffdiff problem--Performed 0 isoform-level transcription difference tests

    如何解决cuffdiff运行结果中表达量为0的情况? cuffdiff -o cdiffout -b ref.fasta -u -p 15 --library-type fr-firststrand ...

  5. springboot---aop切片编程

    1.介绍 面向切面编程,关注点代码与业务代码分离,就是给指定方法执行前执行后..插入重复代码 关注点:重复代码 切面:被切面的类 切入点:执行目标对象方法,动态植入切片代码 2.部署步骤 2.1:添加 ...

  6. HDU 4348 To the moon (主席树区间更新)

    题意:首先给你n个数,开始时间为0,最后按照操作输出 给你四种操作: 1. C l r d :  在(l,r)区间都加上d,时间加一2. Q l r :  询问现在(l,r)的区间和3. H l r ...

  7. Java -- DBUtils 框架 操作MySQL数据库

    1. 增删改查 常用Handler处理器示例 QueryRunner类提供了两个构造方法: •默认的构造方法 •需要一个 javax.sql.DataSource来作参数的构造方法.   public ...

  8. Redis简介 & 与Memcache的区别

    redis 是一个基于内存的高性能key-value数据库.   Reids的特点 Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库统统加载在内存当中进行操 ...

  9. android自定义日期组件之双DatePicker

    1.效果图(两个DatePicker放在一起,同时选择起始与结束时间): 2.实现 2.1布局文件: <?xml version="1.0" encoding="u ...

  10. Maven下载 || 配置本地仓库 || IntelliJ IDEA配置Maven教程

    本文章主要介绍1.Maven下载   2.配置本地仓库Repository   3.IDEA配置Maven 三点. 相关博客: Eclipse配置Maven https://www.cnblogs.c ...