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

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

   <configSections>
      <section />
      <sectionGroup />
      <remove />
      <clear/>
   </configSections>

屬性和項目

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

屬性

無。

子項目

項目

描述

clear

移除繼承區段和區段群組的所有參考,只允許目前 sectionsectionGroup 項目所加入的區段和區段群組。

remove

移除繼承區段和區段群組的參考。

section

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

sectionGroup

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

父項目

項目

描述

configuration

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

備註

configSections 項目會指定組態區段和處理常式宣告。 這是必要的,因為 ASP.NET 並不會假設組態檔中設定的處理方式, 相反地,ASP.NET 會將組態資料的處理委派給組態區段處理常式。

每個 section 項目都會識別一個組態區段或項目,以及處理組態區段或項目的關聯 ConfigurationSection 衍生類別。 section 項目也可在 sectionGroup 項目中形成邏輯群組,如此即可組織 section 項目並防止命名衝突。 configSections 項目中包含有 section 和 sectionGroup 項目。

如果 configSections 項目位於組態檔中,configSections 項目就必須是 configuration 項目的第一個子項目。

預設組態

.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>
      <section name="sampleSection"
               type="System.Configuration.SingleTagSectionHandler" />
   </configSections>

   <sampleSection setting1="Value1" 
                  setting2="value two" 
                  setting3="third value" />

</configuration>

項目資訊

組態區段處理常式

不套用。

組態成員

ConfigurationSectionCollection

ConfigurationSectionGroupCollection

可設定的位置

Machine.config

根層次的 Web.config

應用程式層級的 Web.config

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

需求

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

.NET Framework 1.0、1.1 或 2.0 版

Microsoft Visual Studio 2003 或 Visual Studio 2005

請參閱

參考

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

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

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

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

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

概念

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

編輯 ASP.NET 組態檔

ASP.NET 組態案例

其他資源

一般組態設定 (ASP.NET)

ASP.NET 組態設定

ASP.NET 組態檔

ASP.NET 網站管理

ASP.NET 組態 API