次の方法で共有


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="Fully qualified class name,assembly file name,version,culture,public key token"

定義はアセンブリ参照と一致する必要があります。たとえば、次のコード例のバージョン番号がアセンブリと一致しなかった場合、エラーになります。

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

共通言語ランタイムおよび .NET Framework アプリケーションで使用されるすべての構成ファイルで必要なルート要素を指定します。

configSections

構成セクションと名前空間の宣言を指定します。

sectionGroup

構成セクション ハンドラと構成セクションの間の関連付けを定義します。

解説

sectionGroup 要素は、section 要素のコンテナとして機能します。section 要素は、構成セクション ハンドラを構成要素または構成セクションに関連付けます。この処理が必要なのは、ASP.NET が構成ファイル内の設定の処理方法について推測を一切行わないからです。代わりに、ASP.NET は構成データの処理を構成セクション ハンドラにデリゲートします。各 section 要素は、構成セクションまたは構成要素と、その構成セクションまたは構成要素を処理する ConfigurationSection クラスの派生関連クラスを示します。section 要素を sectionGroup 要素に論理的にグループ化すると、 section 要素を整理し、名前の競合を防ぐことができます。section 要素と sectionGroup 要素は、configSections 要素に格納されます。

既定の構成

.NET 構成要素の構成セクションは Machine.config ファイルで定義されますが、数が非常に多いため、ここでは紹介していません。system.web セクションの authentication 要素に対する構成セクション ハンドラを定義する Machine.config ファイルの一部を以下に示します。次に、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 Version 2.0

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 Web サイトの管理

ASP.NET 構成 API