共用方式為


General Attributes Inherited by Section Elements 

ASP.NET applies configuration settings to resources in a hierarchical manner. Configuration settings are inherited from parent configuration files. This topic lists several general attributes that are inherited by all section elements.

Section Elements

Section elements are members of configuration sections. This does not include elements that are members of configuration section groups.

Configuration section declarations appear at the top of the configuration file inside the configSections element. Each declaration contained in a section element specifies the name of a section and the name of the .NET Framework class (derived from ConfigurationSection) that processes configuration data in that section. section tags can be grouped in sectionGroup tags.

For more information, see ASP.NET Configuration Files or Format of ASP.NET Configuration Files.

General Attributes

The following table describes the general attributes that can be set for any section elements. These general attributes are also inherited by child elements of the section elements. All the attributes whose names include the work lock are designed to protect the specified content in the configuration file from being changed. No element or attribute is locked by default.

Attribute Description

configSource

Optional String attribute.

Specifies the name of the include file in which the associated configuration section is defined, if such a file exists. Programmatically accessible through the ConfigSource property.

When you use the configSource attribute, you must move the entire section to a separate file because there is no merging of element settings. Any change to the external file causes the application to restart by default. To change this behavior so that the application does not restart after every change, you can configure the section Element for configSections (General Settings Schema) in the Web.config file and set its restartOnExternalChanges attribute to false.

lockAllAttributesExcept

Optional String attribute; the value can be a comma-delimited list.

Locks all attributes of the parent element except the ones specified.

Programmatically accessible through the LockAllAttributesExcept property.

Lower levels of the configuration hierarchy can never lock levels that are above them in the hierarchy.

lockAllElementsExcept

Optional String attribute; the value can be a comma-delimited list.

Locks all child elements of the parent element except the ones specified.

Programmatically accessible through the LockAllElementsExcept property.

lockAttributes

Optional String attribute; the value can be a comma-delimited list.

Locks all attributes of the parent element.

Programmatically accessible through the LockAttributes property.

lockElements

Optional String attribute; the value can be a comma-delimited list.

Locks all child elements of the parent element.

Programmatically accessible through the LockElements property.

lockItem

Optional String attribute.

true if the element on which the attribute occurs should be locked; otherwise, false. The default is false.

This attribute, besides being used to lock any individual element, can also be used on collection elements to lock them specifically within a specified collection. Also, the attribute can be used to lock any entire section.

Programmatically accessible through the LockItem property.

Example

The following code example is a portion of the Machine.config file. Configuration section handlers are declared for the system.web section group and the anonymousIdentification section. Below that, the system.Web and anonymousIdentification configuration elements are declared.

The system.Web configuration element is a member of a configuration section group, which means it does not contain any attributes.

The anonymousIdentification configuration element is a member of a configuration section; therefore, it inherits the attributes listed in the preceding table. Note that its configSource attribute has an external file assigned to it (to contain the content of the element), and that the lockItem attribute is set to true to prevent changes to its content.

<configuration>

  <configSections>
    <!-- Other configuration sections. -->
    <sectionGroup name="system.web" ...>
      <section name="anonymousIdentification" ... />
    </sectionGroup>
  </configSections>

  <system.web>
    <anonymousIdentification  configSource="IDSourceFile.xml" 
       lockItem="true" />
  </system.web>

</configuration>

See Also

Tasks

How to: Lock ASP.NET Configuration Settings

Concepts

ASP.NET Configuration Overview
ASP.NET Configuration Scenarios
Securing ASP.NET Configuration
Format of ASP.NET Configuration Files

Other Resources

ASP.NET Configuration Files