SectionDefinition 类

定义

定义配置节。

public ref class SectionDefinition sealed
public sealed class SectionDefinition
type SectionDefinition = class
Public NotInheritable Class SectionDefinition
继承
SectionDefinition

示例

以下示例演示如何定义配置节以及定义该部分的设置。


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;

namespace AdministrationSnippets
{
    public class AdministrationSectionDefinition
    {
        // List all configuration sections in applicationHost.config
        public void ShowAllSections()
        {
            ServerManager manager = new ServerManager();
            SectionGroup rootGroup = 
                manager.GetApplicationHostConfiguration().RootSectionGroup;
            ShowGroup(rootGroup, -1);

        }

        private void ShowGroup(SectionGroup group, int indentLevel)
        {
            Console.Write("".PadLeft(++indentLevel, ' '));
            string grpName = String.IsNullOrEmpty(group.Name) ? "{root}" : group.Name;
            Console.WriteLine("+ Section Group: {0}; Sub-groups: {1}; Sections: {2}",
                grpName, group.SectionGroups.Count, group.Sections.Count);

            foreach (SectionGroup grp in group.SectionGroups)
            {
                ShowGroup(grp, indentLevel);
            }

            string path = String.Concat(group.Name, "/");

            foreach (SectionDefinition def in group.Sections)
            {
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_Name:                {0}", String.Concat(path,def.Name));
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_AllowDefinition:     {0}", def.AllowDefinition);
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_AllowLocation:       {0}", def.AllowLocation);
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_OverrideModeDefault: {0}", def.OverrideModeDefault);
                Console.Write("".PadLeft(indentLevel, ' '));
                Console.WriteLine("|_Type:                {0}\r\n", 
                    String.IsNullOrEmpty(def.Type) ? "null" : def.Type);
            }
        }

    }
}

注解

声明配置节可定义配置文件的新元素。 新元素包含配置节处理程序读取的设置。 你定义的节的属性和子元素取决于用于读取设置的节处理程序。

以下 <configuration> 元素包含 类所表示的 <section> 元素 SectionDefinition 的示例。

<configuration>

<configSections>

<section name="sampleSection"

type="System.Configuration.SingleTagSectionHandler"

allowLocation="false"/>

</configSections>

<sampleSection setting1="Value1" setting2="value two"

setting3="third value" />

</configuration>

属性

AllowDefinition

获取或设置一个值,该值指示配置节的有效配置路径位置。

AllowLocation

获取或设置一个值,该值指示配置节是否允许 location 属性。

Name

获取当前配置节定义的名称。

OverrideModeDefault

获取或设置当前配置节的默认重写行为。

RequirePermission

定义配置节。

Type

获取或设置实现配置节并可以解释持久化 XML 的类的类型名称。

适用于