zoukankan      html  css  js  c++  java
  • 配置文件的继承与覆盖: Machine.config / Web.config /子目录 Web.config

    C#有三种级别的配置文件:

    机器级别      machine.config  在 C:WindowsMicrosoft.NETFramework64v4.0.30319Configmachine.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;
                }
            }
        }
    }
  • 相关阅读:
    【Kubernetes学习笔记】-kubeadm 手动搭建kubernetes 集群
    教你快速搭建NFS服务
    【Kubernetes学习笔记】-服务访问之 IP & Port & Endpoint 辨析
    【Kubernetes学习笔记】-使用Minikube快速部署K8S单机学习环境
    Linux RDP 会话中无法打开VSCode 解决办法
    Jenkins 凭证管理
    linux 后台运行进程:& , nohup
    使用私有gitlab搭建gitbook持续集成
    VS Code 使用
    Markdown Rules 详解
  • 原文地址:https://www.cnblogs.com/adolphyang/p/4833349.html
Copyright © 2011-2022 走看看