Share via


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

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

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

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

特性和元素

以下几节描述了特性、子元素和父元素。

特性

特性

说明

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

请参见

参考

configSections 元素(常规设置架构)

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

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

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

configuration 元素(常规设置架构)

概念

ASP.NET Configuration File Hierarchy

Format of ASP.NET Configuration Files

Configuration Inheritance

其他资源

常规配置设置 (ASP.NET)

ASP.NET 配置设置

ASP.NET Configuration Files

Configuring ASP.NET Applications

ASP.NET Configuration API