首页 > Web开发 > 详细

web.config 研究

时间:2019-10-29 19:31:13      阅读:79      评论:0      收藏:0      [点我收藏+]

一、将配置映射成类

1、配置中增加

    <configSections>
        <section name="appConfiguration" type="OilDigital.CGGL.AppConfig.AppConfigurationHandler,OilDigital.CGGL.AppConfig,Culture=neutral, PublicKeyToken=null" />
        
    </configSections>
<appConfiguration>
        <EnterPriseName>中石油</EnterPriseName>
</appConfiguration>

2、类

public class AppConfiguration:System.Configuration.ConfigurationSection
    {
        public AppConfiguration()
        {
            
        }

        /// <summary>
        /// 企业名称
        /// </summary>
        [ConfigurationProperty("EnterPriseName", DefaultValue = "工程建设公司")]
        public string  EnterPriseName
        {
            get { return (string)this["EnterPriseName"]; }
            set { this["EnterPriseName"] = value; }
        }
}

3、使用

AppConfiguration config =(AppConfiguration)System.Configuration.ConfigurationManager.GetSection("appConfiguration");

 

web.config 研究

原文:https://www.cnblogs.com/zhengwei-cq/p/11760486.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!