SectionDefinition Class
Collapse the table of content
Expand the table of content

SectionDefinition Class

IIS 7.0

Defines a configuration section.


Namespace:  Microsoft.Web.Administration
Assembly:  Microsoft.Web.Administration (in Microsoft.Web.Administration.dll)

public sealed class SectionDefinition

The SectionDefinition type exposes the following members.

Public propertyAllowDefinitionGets or sets a value indicating valid configuration path locations for the configuration section.
Public propertyAllowLocationGets or sets a value indicating whether the configuration section allows the location attribute.
Public propertyNameGets the name of the current configuration section definition.
Public propertyOverrideModeDefaultGets or sets the default override behavior for the current configuration section.
Public propertyRequirePermission
Public propertyTypeGets or sets the type name of a class that implements the configuration section and can interpret the persisted XML.

Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodToString (Inherited from Object.)

Declaring a configuration section defines a new element for the configuration file. The new element contains settings that a configuration section handler reads. The attributes and child elements of a section you define depend on the section handler you use to read your settings.

The following <configuration> element contains an example of the <section> element that the SectionDefinition class represents.



<section name="sampleSection"




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

setting3="third value" />


The following example shows how to define a configuration section and to define settings for that section.

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 = 
            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);


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

© 2015 Microsoft