다음을 통해 공유


<section> Element

Contains a configuration section declaration.

<configuration>
   <configSections>
      <section>

<configuration>
   <configSections>
      <sectionGroup>
         <section>

<section
   name="section name"
   type="configuration section handler class, assembly"
   allowDefinition="Everywhere|MachineOnly|MachineToApplication" 
   allowLocation="true|false" />

Required Attributes

Attribute Description
name Specifies the name of the configuration section.
type Specifies the name of the configuration section handler class that reads the section from the configuration file.

Optional Attributes

The following attributes are applicable only for ASP.NET applications. The configuration system ignores these attributes when other types of applications are running.

Attribute Description
allowDefinition Specifies which configuration file the section can be used in. Use one of the following values:
Everywhere
Allows the section to be used in any configuration file. This is the default.
MachineOnly
Allows the section to be used only in the machine configuration file (Machine.config).
MachineToApplication
Allows the section to be used in the machine configuration file or the application configuration file.
allowLocation Determines whether the section can be used within the <location> element. Use one of the following values:
true
Allows the section to be used within the <location> element. This is the default.
false
Does not allow the section to be used within the <location> element.

Remarks

Declaring a configuration section essentially defines a new element for the configuration file. The new element contains settings that a configuration section handler (that is, a class that implements the IConfigurationSectionHandler Interface) reads. The attributes and child elements of a section you define depend on the section handler you use to read your settings.

Declaring a configuration section handler in the Machine.config file enables you to use the configuration section in any application configuration file on that computer, unless the allowDefinition attribute specifies otherwise.

Example

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

<configuration>
   <configSections>
      <section name="sampleSection"
               type="System.Configuration.SingleTagSectionHandler" 
               allowLocation="false"/>
   </configSections>
   <sampleSection setting1="Value1" setting2="value two" 
                  setting3="third value" />
</configuration>

Configuration File

This element can be used in the application configuration file, machine configuration file (Machine.config), and Web.config files that are not at the application directory level.

See Also

Custom Element for NameValueSectionHandler and DictionarySectionHandler | Custom Element for SingleTagSectionHandler | Configuration Section Settings | <sectionGroup> Element | Configuration Sections Schema