配置文件的继承与覆盖: Machine.config / Web.config /子目录 Web.config
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的更多相关文章
- 配置子目录Web.config使其消除继承,用虚拟目录创建多个网站的方法
来源:http://www.wtnzone.com/post/2011/02/20/Set-Web-Config-to-Turn-Inheritance-Off.aspx ASP.NET提供了强大的W ...
- 配置子目录Web.config使其消除继承,iis7.0设置路由
iis7.0设置路由 ,url转向,伪静态 <system.webServer> <modules runAllManagedModulesForAllRequests=& ...
- C# Webservice 解决在运行配置文件中指定的扩展时出现异常。 ---> System.Web.HttpException: 超过了最大请求长度问
摘自: http://blog.csdn.net/gulijiang2008/article/details/4482993 请在服务器端配置 方法一: 在通过WebService处理大数据量数据时出 ...
- 关于Web.config的debug和release.config文件
使用Web.Config Transformation配置灵活的配置文件 发布Asp.net程序的时候,开发环境和发布环境的Web.Config往往不同,比如connectionstring等.如果常 ...
- Web读取指定的config文件的内容
需求: 什么时候会用到动态改变Web.config内的值? 在Web.config定义了一个全局设置值A,因为程序运行中满足了某个条件,要将A的值改变 Web.config中定义: <appSe ...
- 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{ ...
- web php wrong nginx config
web php wrong nginx config 目录 web php wrong nginx config 题目描述 解题过程 信息收集 robots.txt hint.php Hack.php ...
- Web.config Transformation Syntax for Web Application Project Deployment
Web.config Transformation Syntax for Web Application Project Deployment Other Versions Updated: Ma ...
- App.config使用ASP.NET Web Project的Transformation
1.创建对应configuration的App.config文件,比如:App.Debug.config.App.Release.config. 2.编辑项目文件,将App.*.config文件的Bu ...
随机推荐
- hadoop实战项目:查找相同字母组成的字谜
前面我们学习了MapReduce编程思想和编程示例,那么本节课程同学们一起操练操练,动手完成下面的项目. 项目需求 一本英文书籍包含成千上万个单词或者短语,现在我们需要在大量的单词中,找出相同字母组成 ...
- js 职责链模式简要介绍
定义: 使多个对象都有机会处理请求,避免发送者与接受者之间的耦合关系,将对象连成一条链,沿着这条链传递请求,直到有一个对象处理它. 如何把对象串联起来?解决方法通常是将另一个对象作为新创建对象的参数, ...
- Cocos2d-x项目移植到WP8系列之一:前传
原文链接: http://www.cnblogs.com/zouzf/p/3969993.html 许久没动笔了,随想一直都有动笔的想法,但拖来拖去,归根到底还是一个懒字吧 .发现人的惰性真是太强大了 ...
- K8s + Flannel 网络架构图
这是Flannel官网给出的网络架构图 这是通过自己的理解画的逻辑结构图 查看bridge [root@node01 ~]# brctl show bridge name bridge id STP ...
- bat定时检测系统服务是否开启
@echo offrem 定义循环间隔时间和监测的服务:set secs=90set srvname="Apache2a" echo.echo ================== ...
- 偏远小渔村选手的noip2017游记
这次noip估计是我初中最后一次比赛了,毕竟初三狗还要准备中考,要是中考挂了就GG了. 在最终成绩的榜上,我看到我成绩400,非常意外(你们这群大佬赛前天天奶我,还好不是毒奶),更意外的是全省竟然只有 ...
- jquery02-jQuery效果=隐藏和显示+切换+淡入淡出+滑动+动画+回调+链
隐藏和显示 $(selector).hide(speed,callback); $(selector).show(speed,callback); 可选的 speed 参数规定隐藏/显示的速度, ...
- (转) Nova是如何统计OpenStack资源
引言 运维的同事常常遇到这么四个问题: Nova 如何统计 OpenStack 计算资源? 为什么 free_ram_mb, free_disk_gb 有时会是负数? 即使 free_ram_mb, ...
- JavaScriptSerializer 日期处理 JSON.Net
[WebMethod(Description = "取得所有人员 自带json")] [SoapHeader("key")] [ScriptMethod(Res ...
- doeNET Framework 农历 ChineseLunisolarCalendar
C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe test.cs # test.cs using System; using System.Diagnos ...