configSections 元素(常规设置架构)

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

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

特性和元素

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

特性

无。

子元素

元素

说明

clear

移除对继承的节和节组的所有引用,只允许由当前 sectionsectionGroup 元素添加的节和节组。

remove

移除对继承的节和节组的引用。

section

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

sectionGroup

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

父元素

元素

说明

configuration

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

备注

configSections 元素指定了配置节和处理程序声明。 由于 ASP.NET 不对如何处理配置文件内的设置作任何假设,因此这非常必要。 但 ASP.NET 会将配置数据的处理委托给配置节处理程序。

每个 section 元素标识一个配置节或元素以及对该配置节或元素进行处理的关联 ConfigurationSection 派生类。 可以在 sectionGroup 元素中对 section 元素进行逻辑分组,以对 section 元素进行组织并避免命名冲突。 section 和 sectionGroup 元素包含在 configSections 元素中。

如果配置文件中包含 configSections 元素,则 configSections 元素必须是 configuration 元素的第一个子元素。

默认配置

.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>
      <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 信息服务 (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