共用方式為


configSections 的 sectionGroup 項目 (一般設定結構描述)

在組態區段處理常式和組態區段之間定義關聯。

<sectionGroup 
   name="section name"
   type="configuration section handler class, assembly file name, version, culture, public key token">
   <section />
/>

屬性和項目

下列各節將說明屬性、子項目和父項目。

屬性

屬性

描述

name

必要的 String 屬性。

指定與 type 屬性指定之組態區段處理常式關聯的組態區段或項目的名稱。 這也是 group 項目出現在組態檔中區段設定區域的名稱。

type

必要的 String 屬性。

指定組態區段處理常式類別的名稱,該類別處理 name 屬性中指定之區段或項目的組態設定處理。 請使用下列格式:

type="完整類別名稱, 組件檔名稱, 版本, 文化特性, 公開金鑰語彙基元"

定義必須符合組件 (Assembly) 參考。 例如,如果下列程式碼範例中的版本號碼不符合組件,便會發生錯誤。

type="MyConfigSectionHandler.MyHandler,MyCustomConfigurationHandler,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"

組件檔案與定義其本身的 Web.config 檔,都必須位於相同的應用程式目錄。 如果是根 Web.config 或 Machine.config 檔,組件檔案就必須在 %SystemRoot%\Microsoft.NET\Framework\version 目錄中。

子項目

項目

描述

section

在組態區段處理常式和組態項目之間定義關聯。

sectionGroup

在組態區段處理常式和組態區段之間定義關聯。

父項目

項目

描述

configuration

指定 Common Language Runtime 和 .NET Framework 應用程式所使用之每個組態檔中需要的根項目 (Root Element)。

configSections

指定組態區段和命名空間宣告。

sectionGroup

在組態區段處理常式和組態區段之間定義關聯。

備註

sectionGroup 項目可做為 section 項目的容器使用。 section 項目會將組態區段處理常式與組態項目或區段產生關聯。 這是必要的,因為 ASP.NET 並不假設組態檔中設定的處理方式, 相反地,ASP.NET 會將組態資料的處理委派給組態區段處理常式。 每個 section 項目都會定義組態區段或項目,以及由處理組態區段或項目之 ConfigurationSection 類別所衍生的關聯類別。 section 項目可在 sectionGroup 項目中形成邏輯群組,以組織 section 項目並防止命名衝突。 configSections 項目中包含有 section 和 sectionGroup 項目。

預設的組態

.NET 組態項目的組態區段都在 Machine.config 檔中定義,由於數量繁多,無法在此一一列出。 下列摘錄來自 Machine.config 檔案,會定義 system.web 區段 authentication 項目的組態區段處理常式。 然後,定義 authentication 項目的組態設定。

如果組態區段處理常式與組態項目沒有關聯,ASP.NET 便會發出伺服器錯誤:「無法辨認的組態區段 element_name」。

<configuration>
    <configSections>
        <sectionGroup name="system.web" type="System.Web.Configuration.SystemWebSectionGroup, System.Web, Version=%ASSEMBLY_VERSION%, Culture=neutral, PublicKeyToken=%MICROSOFT_PUBLICKEY%">
            <section name="authentication" type="System.Web.Configuration.AuthenticationSection, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication" />
            <!-- Other system.web sections -->
        </sectionGroup>
        <!-- Other configuration sections -->
    </configSections>

    <system.web>
        <authentication mode="Windows">
            <forms name=".ASPXAUTH" 
                   loginUrl="login.aspx" defaultUrl="default.aspx" 
                   protection="All" 
                   timeout="30" 
                   path="/" 
                   requireSSL="False" 
                   slidingExpiration="True" 
                   cookieless="UseCookies" 
                   domain="" 
                   enableCrossAppRedirects="False">
                <credentials passwordFormat="SHA1" />
            </forms>
            <passport redirectUrl="internal" />
        </authentication>
        <!-- Other system.web elements -->
    </system.web>
    <!-- Other configuration settings -->
</configuration>

範例

下列程式碼範例示範如何宣告區段群組,以及在區段群組內宣告區段。

<configuration>
   <configSections>
      <sectionGroup name="mySectionGroup">
         <section name="mySection"
            type="System.Configuration.NameValueSectionHandler" />
      </sectionGroup>
   </configSections>
   <mySectionGroup>
      <mySection>
         <add key="key1" value="value1" />
      </mySection>
   </mySectionGroup>
</configuration>

項目資訊

組態區段處理常式

不套用。

組態成員

ConfigurationSectionGroup

可設定的位置

Machine.config

根層次的 Web.config

應用程式層級的 Web.config

虛擬或實體目錄層級的 Web.config

需求

Microsoft Internet Information Services (IIS) 5.0、5.1 或 6.0 版

.NET Framework 2.0 版

Microsoft Visual Studio 2003 或 Visual Studio 2005

請參閱

參考

configSections 項目 (一般設定結構描述)

configSections 的 section 項目 (一般設定結構描述)

configSections 的 clear 項目 (一般設定結構描述)

configSections 的 remove 項目 (一般設定結構描述)

configuration 項目 (一般設定結構描述)

概念

ASP.NET 組態檔階層架構和繼承

編輯 ASP.NET 組態檔

ASP.NET 組態案例

其他資源

一般組態設定 (ASP.NET)

ASP.NET 組態設定

ASP.NET 組態檔

ASP.NET 網站管理

ASP.NET 組態 API