다음을 통해 공유


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

구성 섹션에서 위치 특성을 허용하는지 여부를 나타내는 값을 가져오거나 설정합니다.

Name

현재 구성 섹션 정의의 이름을 가져옵니다.

OverrideModeDefault

현재 구성 섹션에 대한 기본 재정의 동작을 가져오거나 설정합니다.

RequirePermission

구성 섹션을 정의합니다.

Type

구성 섹션을 구현하고 지속형 XML을 해석할 수 있는 클래스의 형식 이름을 가져오거나 설정합니다.

적용 대상