zoukankan      html  css  js  c++  java
  • 配置节点简单使用

    在web开发中一般我们读取web.config里面的信息,都是通过
    WebConfigurationManager.AppSettings
    WebConfigurationManager.ConnectionStrings
    或者时候1.1里面老的方式实现IConfigurationSection,其实都无所谓了。
    这里主要讨论一下使用ConfigurationSection抽象类的方式,定义配置节,可以实现多配置节,其实和IConfigurationSection一样,没感觉有什么很大区别。做个笔记而已了
    首先web.config
    1<configSections>
    2  <section name="mqtest" type="test, __code"/>
    3</configSections>
    4<mqtest>
    5  <aaForm asdfa="10"></aaForm>
    6</mqtest>
    调用
     1
     2/// <summary>
     3/// 配置节的访问
     4/// </summary>

     5public class test : ConfigurationSection
     6{
     7    //元素
     8    [ConfigurationProperty("aaForm", IsRequired = true)]
     9    public aaFormElement aaForm
    10    {
    11        get return (aaFormElement)base["aaForm"]; }
    12    }

    13
    14    [ConfigurationProperty("time")]
    15    public DateTime Time
    16    {
    17        get return (DateTime)this["time"]; }
    18        set this["time"= value; }
    19    }

    20
    21    [ConfigurationProperty("tt")]
    22    public int tt
    23    {
    24        get return (int)this["tt"]; }
    25        set this["tt"= value; }
    26    }

    27
    28    public override bool IsReadOnly()
    29    {
    30        return false;
    31    }

    32}

    33
    34///配置节文件中的配置元素
    35public class aaFormElement : ConfigurationElement
    36{
    37
    38    [ConfigurationProperty("asdfa", DefaultValue = "10")]
    39    public string aaaa
    40    {
    41        get return (string)base["asdfa"]; }
    42        set base["asdfa"= value; }
    43    }

    44}

    45
    页面访问
    test Settings1 = (test)WebConfigurationManager.GetSection("mqtest");
    Settings1.tt 
    = 100;

    ==============直接取属性
    <system.web>
         
    <httpRuntime maxRequestLength="4096" executionTimeout="120" ></httpRuntime>
    </system.web>
    Configuration config = WebConfigurationManager.OpenWebConfiguration(this.Request.ApplicationPath);
     HttpRuntimeSection myHttpRuntimeSection 
    = (HttpRuntimeSection)config.GetSection("system.web/httpRuntime");



    demo
  • 相关阅读:
    面试官:软件测试没搞懂这些,哪里来的自信投简历? 刁钻问得高频的面试题(含答案)
    软件测试行业的职业素养?——《高级软件测试-高级软件测试分析师》第一章
    什么?你正在学web自动化测试?那这些Selenium的基本操作你了解过吗?
    没想到 Google 排名第一的编程语言,为什么会这么火?
    为什么大家都在用Fiddler?
    看了很多文章,就这篇说明白了什么是接口测试(含视频教程)
    Win 10 安裝 Docker 及相關設置
    Dynamics CRM
    Dynamics CRM
    Dynamics CRM
  • 原文地址:https://www.cnblogs.com/ant520/p/964434.html
Copyright © 2011-2022 走看看