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. 使用bedtools的一个问题

    问题:有两个平行测序样本,分别得到1.vcf和2.vcf两个文件,想知道这两个文件有多少个重合点. [wangjq@mgmt CHG029194]$ cat t1 chr1 10 10 chr1 11 ...

  2. linux+java+webdriver chrome handless无界面启动

    网上现有的解决方案要么是windows下的,要么是python的,搞了一天终于解决了,记录如下. 1 下载chrome linux版和对应版本的webdriver,我这里使用的是chrome66和ch ...

  3. MySQL数据库基本操作(一)

    进入mysql 本地连接: mysql -u用户名 -p 输入密码 qwe123 mysql -uroot -pqwe123 sudo apt-get install mysql-server # p ...

  4. Docker 数据管理-tmpfs mounts

    Use tmpfs mounts Volumes and bind mounts are mounted into the container’s filesystem by default, and ...

  5. 常用的python 库地址

    来源   https://pypi.python.org/pypi wordcloud  https://github.com/amueller/word_cloud.git jieba https: ...

  6. Android Sqlite 批量插入性能优化

    db.beginTransaction(); try { for (...) { db.execSQL("...", new Object[]{}); } db.setTransa ...

  7. Canvas - Web API

    <canvas> 是 HTML5 新增的元素,可用于通过使用JavaScript中的脚本来绘制图形.例如,它可以用于绘制图形,制作照片,创建动画,甚至可以进行实时视频处理或渲染. Mozi ...

  8. JS循环遍历JSON数据的方法

    JSON数据如:{"options":"[{/"text/":/"王家湾/",/"value/":/" ...

  9. GridView的简单使用

    测试代码: activity_main.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/a ...

  10. 《ASP.NET夜话》 - 书摘精要

    (P14) 如果客户端启用了Cookie,那么客户端与服务器之间通过Cookie来传递SessionID的值:如果客户端没有启用Cookie,就会通过URL来传递SessionID的值: (P15) ...