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-код.

Применяется к