다음을 통해 공유


<clear> Element for <configSections>

Clears all previously defined sections and section groups.

<configuration>
   <configSections>
**      <clear>**

<clear/>

Remarks

The <clear> element removes all sections and section groups from your application that were defined earlier in the current configuration file or 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 two sections, <sampleSection> and <anotherSampleSection>, which are read before the application configuration file.

<!-- Machine.config file. -->
<configuration>
   <configSections>
      <section name="sampleSection"
               type="System.Configuration.SingleTagSectionHandler" />
      <section name="anotherSampleSection"
               type="System.Configuration.NameValueSectionHandler" />
   </configSections>
   <sampleSection setting1="Value1" setting2="value two" 
                  setting3="third value" />
</configuration>

The following application configuration file code clears all previously declared sections. The application cannot use or retrieve settings in either of the sections that were declared in the machine configuration file. However, it can use settings from <anotherSection> because it comes after the <clear> element.

<!-- Application configuration file. -->
<configuration>
   <configSections>
      <clear/>
      <section name="anotherSection"
               type="System.Configuration.NameValueSectionHandler" />
    </configSections>
</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