共用方式為


<section> 元素

包含一個配置區段宣告。

<configuration>
  <configSections>
    <section>

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

語法

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

必要屬性

Attribute Description
name 指定配置區段的名稱。
type 指定從設定檔讀取該段的配置區段處理類別名稱。 型別值的語法為「full-qualified-section-handler-class-name, simple-assembly-name」。 簡單的組合名稱是根檔名,沒有 .dll 副檔名。

選用屬性

以下屬性僅適用於 ASP.NET 應用。 組態系統會忽略其他應用程式類型的這些屬性。

選擇性屬性 Description
allowDefinition 指定該區段可用於哪個設定檔。 請使用下列其中一個值:

到處
允許該區段在任何設定檔中使用。 這是預設值。
僅機器
允許該區段僅在機器設定檔中使用(Machine.config)。
機器轉應用程式
允許該區段用於機器設定檔或應用程式設定檔。
allowLocation 判斷該區段是否能在元素中 <location> 使用。 請使用下列其中一個值:


允許該區段在元素中 <location> 使用。 這是預設值。

不允許在元素中 <location> 使用該區段。

父元素

父元素 Description
<configSections> 包含設定區段與命名空間宣告。
<sectionGroup> 定義了設定區段的命名空間。

備註

元素<section>是其中一<configSections><sectionGroup>元素的子元素,但不是兩者的子元素。

子專案

None

備註

宣告設定區段基本上是為設定檔定義一個新的元素。 新元素包含設定,設定區段處理器(即實作 IConfigurationSectionHandler 介面的類別)會讀取這些設定。 你定義的區段的屬性和子元素取決於你用來讀取設定的區段處理器。

Machine.config 檔案中宣告設定區段處理器,允許你在該電腦上的任何應用程式設定檔中使用該組態區段,除非屬性 allowDefinition 另有指定。

Example

以下範例說明如何定義設定區段及該區段的設定:

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

組態檔

此元素可用於應用程式設定檔、機器設定檔(Machine.config)以及非應用程式目錄層級的 Web.config 檔案中。

另請參閱