ASP.NET Syntax ASP.NET Configuration Sections
Represents a grouping of related sections within a configuration file.
<sectionGroup name = "section name"
type = "configuration section handler class, assembly file name, version, culture, public key token"
<section ... />
/>
The following sections describe attributes, child elements, and parent elements.
Attribute |
Description |
name |
Required String attribute.
Specifies the name of the configuration section or element that is associated with the configuration section handler that is specified by the type attribute. This is the name of the group element as it appears in the section settings area of the configuration file. |
type |
Required String attribute.
Specifies the name of the configuration section handler class that handles the processing of the configuration settings that are in the section or element that is specified in the name attribute. Use the following format:
type = " Fully qualified class name, assembly file name, version, culture, public key token"
The definition must match the assembly reference. For example, if the version number in the following code example does not match the assembly, an error occurs.
type = "MyConfigSectionHandler.MyHandler, MyCustomConfigurationHandler,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
The assembly file must be located in the same application directory as the Web.config file that defines it. In the case of the root Web.config or Machine.config file, the assembly file must be in the %SystemRoot%\Microsoft.NET\Framework\version directory. |
Element |
Description |
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. |
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. |
configSections |
Specifies configuration section and namespace declarations. |
sectionGroup |
Defines an association between a configuration section handler and a configuration section. |
The sectionGroup element acts as a container for section elements. A section element associates a configuration section handler with a configuration element or section. This is necessary 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 class that is derived from the ConfigurationSection 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.
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" />
</sectionGroup>
</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>
The following shows an excerpt from the root web.config file of asp.net.ph. The code example shows how a custom configuration section named sourceView ( and the settings for that section ) is defined.
<configuration xmlns = "http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<sectionGroup name = "system.web">
<section name = "sourceView"
type = "System.Configuration.NameValueSectionHandler, System,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<!-- Other configuration settings -->
<system.web>
<sourceView>
<add key = "root" value="d:\web projects\asp.net.ph" />
</sourceView>
<!-- Other system.web settings -->
</system.web>
</configuration>
<configSections> Section <configSections> section Element ConfigurationSectionGroup Class