Поделиться через


<clear> Element for NameValueSectionHandler and DictionarySectionHandler

Clears all previously defined settings in a section.

<configuration>
**      <section name>**
**         <clear>**

<clear/>

Remarks

You can use the <clear> element to remove all settings from your application that were defined at a higher level in the configuration file hierarchy.

Example

The following example shows how to use the <clear> element in an application configuration file to clear sections previously defined in the machine configuration file.

The following machine configuration file code declares the section <mySection>.

<!-- Machine.config file.-->
<configuration>
   <configSections>
      <section name="mySection"
         type="System.Configuration.NameValueSectionHandler,System" />
   </sectionGroup>
   </configSections>
   <mySection>
      <add key="key1" value="value1" />
      <add key="key2" value="value2" />
   </mySection>
</configuration>

The following application configuration file code removes all settings from <mySection>. The application cannot retrieve any of the settings that were declared in the in the <mySection> section of the machine configuration file.

<!-- Application configuration file. -->
<configuration>
   <mySection>
      <clear/>
   </mySection>
</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

Configuration Sections Schema | Configuration Section Settings