Partager via


configSections Element (General Settings Schema)

Specifies configuration section and namespace declarations.

   <configSections>
      <section />
      <sectionGroup />
      <remove />
      <clear/>
   </configSections>

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

None.

Child Elements

Element Description

clear

Removes all references to inherited sections and section groups, allowing only the sections and section groups that are added by the current section and sectionGroup elements.

remove

Removes a reference to an inherited section and section group.

section

Defines an association between a configuration section handler and a configuration element.

sectionGroup

Defines an association between a configuration section handler and a configuration section.

Parent Elements

Element Description

configuration

Specifies the required root element in every configuration file that is used by the common language runtime and the .NET Framework applications.

Remarks

The configSections element specifies configuration section and handler declarations. This is required because ASP.NET makes no presumptions about how to handle settings within a configuration file. Instead, ASP.NET delegates the processing of configuration data to configuration section handlers.

Each section element identifies a configuration section or element and the associated ConfigurationSection-derived class that handles the configuration section or element. The section elements can be logically grouped in sectionGroup elements to organize the section elements and to avoid naming conflicts. The section and sectionGroup elements are contained in the configSections element.

If the configSections element is in a configuration file, the configSections element must be the first child element of the configuration element.

Default Configuration

Configuration sections for the .NET configuration elements are defined in the Machine.config file and are too numerous to list here. The following excerpt from the Machine.config file defines the configuration section handler for the authentication element of the system.web section. Then, configuration settings are defined for the authentication element.

If a configuration section handler is not associated with a configuration element, ASP.NET issues the server error, "Unrecognized configuration section element_name."

<configuration>
    <configSections>
        <sectionGroup name="system.web" type="System.Web.Configuration.SystemWebSectionGroup, System.Web, Version=%ASSEMBLY_VERSION%, Culture=neutral, PublicKeyToken=%MICROSOFT_PUBLICKEY%">
            <section name="authentication" type="System.Web.Configuration.AuthenticationSection, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication" />
            <!-- Other system.web sections -->
        </sectionGroup>
        <!-- Other configuration sections -->
    </configSections>

    <system.web>
        <authentication mode="Windows">
            <forms name=".ASPXAUTH" 
                   loginUrl="login.aspx" defaultUrl="default.aspx" 
                   protection="All" 
                   timeout="30" 
                   path="/" 
                   requireSSL="False" 
                   slidingExpiration="True" 
                   cookieless="UseCookies" 
                   domain="" 
                   enableCrossAppRedirects="False">
                <credentials passwordFormat="SHA1" />
            </forms>
            <passport redirectUrl="internal" />
        </authentication>
        <!-- Other system.web elements -->
    </system.web>
    <!-- Other configuration settings -->
</configuration>

Example

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

<configuration>

   <configSections>
      <section name="sampleSection"
               type="System.Configuration.SingleTagSectionHandler" />
   </configSections>

   <sampleSection setting1="Value1" 
                  setting2="value two" 
                  setting3="third value" />

</configuration>

Element Information

Configuration section handler

Does not apply.

Configuration member

ConfigurationSectionCollection

ConfigurationSectionGroupCollection

Configurable locations

Machine.config

Root-level Web.config

Application-level Web.config

Virtual or physical directory–level Web.config

Requirements

Microsoft Internet Information Services (IIS) version 5.0, 5.1, or 6.0

The .NET Framework version 1.0, 1.1, or 2.0

Microsoft Visual Studio 2003 or Visual Studio 2005

See Also

Reference

configuration Element (General Settings Schema)
section Element for configSections (General Settings Schema)
sectionGroup Element for configSections (General Settings Schema)
clear Element for configSections (General Settings Schema)
remove Element for configSections (General Settings Schema)

Concepts

ASP.NET Configuration File Hierarchy and Inheritance
Format of ASP.NET Configuration Files
ASP.NET Configuration Scenarios

Other Resources

General Configuration Settings (ASP.NET)
ASP.NET Configuration Settings
ASP.NET Configuration Files
Configuring ASP.NET Applications
ASP.NET Configuration API