configSections 的 sectionGroup 元素(常规设置架构)

更新:2007 年 11 月

定义配置节处理程序与配置节之间的关联。

configuration 元素(常规设置架构)
  configSections 元素(常规设置架构)
    configSections 的 sectionGroup 元素(常规设置架构)
      configuration 元素(常规设置架构)
        configSections 元素(常规设置架构)
          configSections 的 sectionGroup 元素(常规设置架构)
            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="完全限定类名,程序集文件名,版本,区域性,公钥标记"

定义必须匹配程序集引用。例如,如果下面的代码示例中的版本号与程序集不匹配,会发生错误。

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

程序集文件必须与定义它的 Web.config 文件位于同一个应用程序目录中。对于根 Web.config 或 Machine.config 文件,程序集文件必须在 %SystemRoot%\Microsoft.NET\Framework\版本目录中。

子元素

元素

说明

section

定义配置节处理程序与配置元素之间的关联。

sectionGroup

定义配置节处理程序与配置节之间的关联。

父元素

元素

说明

configuration

指定公共语言运行库和 .NET Framework 应用程序所使用的每个配置文件中均需要的根元素。

configSections

指定配置节和命名空间声明。

sectionGroup

定义配置节处理程序与配置节之间的关联。

备注

sectionGroup 元素充当 section 元素的容器。section 元素将配置节处理程序与配置元素或节关联。由于 ASP.NET 不对如何处理配置文件内的设置作任何假设,因此这非常必要。但 ASP.NET 会将配置数据的处理委托给配置节处理程序。每个 section 元素均标识一个配置节或元素,以及处理该配置节或元素的 ConfigurationSection 类派生的关联类。可以在 sectionGroup 元素中对 section 元素进行逻辑分组,以对 section 元素进行组织并避免命名冲突。section 和 sectionGroup 元素包含在 configSections 元素中。

默认配置

.NET 配置元素的配置节在 Machine.config 文件中定义,因内容较多,恕不在此列出。下面的内容摘自 Machine.config 文件,用于定义 system.web 节中 authentication 元素的配置节处理程序。然后,定义 authentication 元素的配置设置。

如果配置节处理程序不与某个配置元素关联,ASP.NET 将发出服务器错误“无法识别的配置节元素名称”。

<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 信息服务 (IIS) 版本 5.0、5.1 或 6.0

.NET Framework 2.0 版

Microsoft Visual Studio 2003 或 Visual Studio 2005

请参见

概念

ASP.NET 配置文件层次结构和继承

编辑 ASP.NET 配置文件

ASP.NET 配置方案

参考

configSections 元素(常规设置架构)

configSections 的 section 元素(常规设置架构)

configSections 的 clear 元素(常规设置架构)

configSections 的 remove 元素(常规设置架构)

configuration 元素(常规设置架构)

其他资源

常规配置设置 (ASP.NET)

ASP.NET 配置设置

ASP.NET 配置文件

管理 ASP.NET 网站

ASP.NET 配置 API