Share via


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 を解釈できるクラスの型名を取得または設定します。

適用対象