<configSections> 的 <clear> 項目
清除所有先前定義的區段和區段群組。
<configuration>
<configSections>
<clear>
<clear/>
備註
<clear> 項目會從您的應用程式中移除所有先前已在目前組態檔中定義或位於組態檔階層架構較高層級的區段或區段群組。
範例
下列範例顯示如何在應用程式組態檔中使用 <clear> 項目,以清除先前定義在電腦組態檔中的區段。
下列電腦組態檔程式碼宣告兩個在應用程式組態檔之前讀取的區段:<sampleSection>
和 <anotherSampleSection>
。
<!-- 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>
下列應用程式組態檔程式碼會將所有先前宣告的區段清除。應用程式無法使用或擷取任何一個已在電腦組態檔中宣告的區段設定。不過,它可以使用 <anotherSection>
的設定,因為它位於 <clear> 項目之後。
<!-- Application configuration file. -->
<configuration>
<configSections>
<clear/>
<section name="anotherSection"
type="System.Configuration.NameValueSectionHandler" />
</configSections>
</configuration>
組態檔
這個項目可以在不是位於應用程式目錄層級的應用程式組態檔、電腦組態檔 (Machine.config) 和 Web.config 檔案中使用。