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. INDEL的重新比对和碱基质量分数的重新校准

    1.为什么要做这两步(why): indel的重新比对:这是由于比对软件的自身限制,其可能将包括indel的read解释为snp的read,这就导致calling的错误和后面的碱基质量分数的重新校准. ...

  2. jQuery之DOM操作大全

    jQuery属性操作 获取元素属性的语法:attr(name) 例子:$("#img1").attr("src"); 设置元素单个属性的语法:attr(key, ...

  3. PHP 面向对象及Mediawiki 框架分析(一)

    此文是一JAVA哥大神写的,虽然他不懂PHP.我这人PHP半桶水,面向对象更是半桶水都没有,此文原本是为了让我理解MediaWiki的运行机制的,愣是用他的JAVA的面向对象知识,对Mediawiki ...

  4. FreeMarker 使用实例

    以下内容全部是网上收集: FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: 1,文本:直接输出的部分 2,注释:<#-- ... - ...

  5. how to use composer in fiddler

    https://www.cnblogs.com/youxin/p/3570310.html http://docs.telerik.com/fiddler/generate-traffic/tasks ...

  6. hive学习6

    将查询结果集写入另一个表中的时候报了这个错,Dynamic partition strict mode requires at least one static partition column. T ...

  7. Spark基本概念快速入门

      Spark集群 一组计算机的集合,每个计算机节点作为独立的计算资源,又可以虚拟出多个具备计算能力的虚拟机,这些虚拟机是集群中的计算单元.Spark的核心模块专注于调度和管理虚拟机之上分布式计算任务 ...

  8. excel比较筛选两列不一样的数据

    在excel表中,罗列两列数据,用B列数据与A列比较,筛选出B列中哪些数据不同,并用红色标记出来.     首先选中B列.直接鼠标左键点击B列即可选中."开始"--->&qu ...

  9. JSON解析字符串

    JSON解析字符串 JSON 解析字符串时,应按严格的标准,否则无法解析: str1 = '{"str":"string","number" ...

  10. UOJ66 新年的巧克力棒

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...