zoukankan      html  css  js  c++  java
  • ConfigurationSection

    https://msdn.microsoft.com/en-us/library/system.configuration.configurationsection(v=vs.110).aspx

    Remarks

    You use the ConfigurationSection class to implement a custom section type.

    Extend the ConfigurationSection class to provide custom handling and programmatic access to custom configuration sections.

    For information about how use custom configuration sections, see How to: Create Custom Configuration Sections Using ConfigurationSection.

    A section registers its handling type with an entry in the configSections element.

    For an example, see the configuration file excerpt摘录 shown in the Example section.

    Note:

    In previous versions of the .NET Framework, configuration section handlers were used to make changes to configuration settings programmatically.

    Now, all the default configuration sections are represented by classes that extend the ConfigurationSection class.

    Notes to Implementers:

    You can use a programmatic or a declarative (attributed) coding model to create custom configuration sections:

    • Programmatic model. This model requires that for each section attribute you create a property to get or set its value and add it to the internal property bag of the underlying ConfigurationElement base class.

    • Declarative model. This simpler model, also called the attributed model, allows you to define a section attribute by using a property and decorating it with attributes. These attributes instruct the ASP.NET configuration system about the property types and their default values. With this information, obtained through reflection, the ASP.NET configuration system creates the section property objects and performs the required initialization.

    The Configuration class allows programmatic access for editing configuration files.

    You can access these files for reading or writing as follows:

    Reading. You use GetSection or GetSectionGroup to read configuration information. Note that the user or process that reads must have the following permissions:

    • Read permission on the configuration file at the current configuration hierarchy level.

    • Read permissions on all the parent configuration files.

    If your application needs read-only access to its own configuration, it is recommended you use the GetSection overloaded methods in the case of Web applications, or the ConfigurationManager.GetSection method in the case of client applications.

    These methods provide access to the cached configuration values for the current application, which has better performance than the Configuration class.

    Note:

    If you use a static GetSection method that takes a path parameter, the path parameter must refer to the application in which the code is running;

    otherwise, the parameter is ignored and configuration information for the currently-running application is returned.

    Writing. You use one of the Save methods to write configuration information. Note that the user or process that writes must have the following permissions:

    • Write permission on the configuration file and directory at the current configuration hierarchy level.

    • Read permissions on all the configuration files.

    The following example shows how to implement a custom section programmatically.

    For a complete example that shows how to implement and use a custom section implemented using the attributed model, seeConfigurationElement.

    删除section

    如上图所示,需要删除名为fiftyOne的sectiongroup。并且添加一个section为ajaxControlToolKit的section。

     [TestFixture]
        class KenticoUpgrade7To11Test
        {
            [Test]
            public void Test()
            {
                var filePath = @"/";
                var configuration = WebConfigurationManager.OpenWebConfiguration(filePath,"Test");
    
                var sectionGroups = configuration.SectionGroups;
                var sections = configuration.Sections;
    
                var sectionGroupToDelete = "fiftyOne";
                sectionGroups.Remove(sectionGroupToDelete);
    
    
                var sectionToAdd = "ajaxControlToolkit";
                ConfigurationSection section = sections.Get(sectionToAdd);
                var ajaxControlToolkitConfigSection = section as AjaxControlToolkitConfigSection;
                if (ajaxControlToolkitConfigSection == null)
                {
                    //add
                    ajaxControlToolkitConfigSection = new AjaxControlToolkitConfigSection();
                    sections.Add(sectionToAdd, ajaxControlToolkitConfigSection);
                }
                else
                {
                    //update
                }
                ajaxControlToolkitConfigSection.SectionInformation.Type = "AjaxControlToolkit.AjaxControlToolkitConfigSection, AjaxControlToolkit";
                ajaxControlToolkitConfigSection.SectionInformation.RequirePermission = false;
    
                configuration.Save();
            }
        }
  • 相关阅读:
    Python partition() 方法
    汽车车灯灯具系统(下)
    汽车车灯灯具系统(上)
    语义和边缘:从噪声和符号中学习
    AI解决方案:边缘计算和GPU加速平台
    GPU与显卡
    图像处理 100 问!!
    匹配算法:局部结构保留
    图像拼接技术
    SLAM的通用框架:GSLAM
  • 原文地址:https://www.cnblogs.com/chucklu/p/6513665.html
Copyright © 2011-2022 走看看