WebConfigurationManagerとは? わかりやすく解説

WebConfigurationManager クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

Web アプリケーションに適用される構成ファイルにアクセスできるようにします。

名前空間: System.Web.Configuration
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public NotInheritable Class
 WebConfigurationManager
public static class WebConfigurationManager
public ref class WebConfigurationManager abstract
 sealed
public final class WebConfigurationManager
public final class WebConfigurationManager
解説解説

WebConfigurationManager を使用すると、マシン情報やアプリケーション情報にアクセスできます。

Web アプリケーション関連の構成ファイルを処理する場合は、WebConfigurationManager の使用をお勧めします。クライアント アプリケーションの場合は、ConfigurationManager を使用します。

次に説明するように、作成したアプリケーションで System.Configuration 型を拡張したり、それを直接使用して構成情報を処理したりできます。

実装時の注意 Configuration は、構成ファイルの編集をプログラムから行うことができるようにするクラスです。WebConfigurationManager に用意されているオープン メソッドの 1 つを使用します。これらのメソッドは、Configuration オブジェクトを返します。このオブジェクトにより、基になる構成ファイルを処理するために必要なメソッドとプロパティが提供されます。次に示す方法で、これらのファイルへの読み取りアクセスまたは書き込みアクセスができます。

アプリケーションが独自の構成に対する読み取り専用アクセスを行う必要がある場合は、GetSection メソッドを使用することをお勧めします。これらのメソッドにより、現在のアプリケーションのキャッシュされた構成値にアクセスできます。こちらの方が、Configuration クラスよりもパフォーマンスが優れています。
メモメモ

パス パラメータを受け取る静的な GetSection メソッドを使用する場合、パス パラメータは、コードを実行しているアプリケーションを参照している必要があります。そうでない場合は、パラメータが無視され、現在実行中のアプリケーションの構成情報が返されます。

使用例使用例

WebConfigurationManager メソッドを使用して構成情報にアクセスする方法を次のコード例に示します。

' Show the use of GetSection(string). 
' It gets the connectiobStrings section.
' If called from within a client application,
' the GetSection(string) gets the default connectionStrings
' section from the machine.config.
' If called from within a Web aplication it gets the
' section from the configuration file located at the 
' application current level. 
Shared Sub GetSection1()
   
   ' Get the connectionStrings section.
     Dim connectionStringsSection As ConnectionStringsSection
 = _
     WebConfigurationManager.GetSection("connectionStrings")
   
   ' Get the connectionStrings key,value pairs collection.
     Dim connectionStrings As ConnectionStringSettingsCollection
 = _
     connectionStringsSection.ConnectionStrings
   
   ' Get the collection enumerator.
     Dim connectionStringsEnum As IEnumerator
 = _
     connectionStrings.GetEnumerator()
   
   ' Loop through the collection and 
   ' display the connectionStrings key, value pairs.
   Dim i As Integer = 0
   Console.WriteLine("[Display the connectionStrings]")
   While connectionStringsEnum.MoveNext()
      Dim name As String
 = connectionStrings(i).Name
         Console.WriteLine("Name: {0} Value: {1}",
 _
         name, connectionStrings(name))
      i += 1
   End While
   
   Console.WriteLine()
End Sub 'GetSection1


// Show the use of GetSection(string). 
// It gets the connectiobStrings section.
// If called from within a client application,
// the GetSection(string) gets the default connectionStrings
// section from the machine.config.
// If called from within a Web aplication it gets the
// section from the configuration file located at the 
// application current level. 
static void GetSection1()
{

    // Get the connectionStrings section.
    ConnectionStringsSection connectionStringsSection =
        WebConfigurationManager.GetSection("connectionStrings")
        as ConnectionStringsSection;

    // Get the connectionStrings key,value pairs collection.
    ConnectionStringSettingsCollection connectionStrings =
        connectionStringsSection.ConnectionStrings;
   
    // Get the collection enumerator.
    IEnumerator connectionStringsEnum =
        connectionStrings.GetEnumerator();

    // Loop through the collection and 
    // display the connectionStrings key, value pairs.
    int i = 0;
    Console.WriteLine("[Display the connectionStrings]");
    while (connectionStringsEnum.MoveNext())
    {
        string name = connectionStrings[i].Name;
        Console.WriteLine("Name: {0} Value: {1}",
        name, connectionStrings[name]);
        i += 1;
    }

    Console.WriteLine();
}

継承階層継承階層
System.Object
  System.Web.Configuration.WebConfigurationManager
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

WebConfigurationManager プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ AppSettings 現在の Web アプリケーションの既定の構成の AppSettingsSection データを取得します。
パブリック プロパティ ConnectionStrings 現在の Web アプリケーションの既定の構成の ConnectionStringsSection データを取得します。
参照参照

関連項目

WebConfigurationManager クラス
System.Web.Configuration 名前空間
Configuration
ConfigurationManager

その他の技術情報

ASP.NET 構成の概要

WebConfigurationManager メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetSection オーバーロードされます。 現在の Web アプリケーションの既定の構成ファイルの、指定した構成セクションを取得します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド GetWebApplicationSection 現在の Web アプリケーションの構成ファイルの、指定した構成セクションを取得します。
パブリック メソッド OpenMachineConfiguration オーバーロードされます。 マシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
パブリック メソッド OpenMappedMachineConfiguration オーバーロードされます。 マシン構成ファイルを Configuration として開き、読み取りまたは書き込みができるようにします。
パブリック メソッド OpenMappedWebConfiguration オーバーロードされます。 指定したファイル マップを使用して、Web アプリケーション構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
パブリック メソッド OpenWebConfiguration オーバーロードされます。 Web アプリケーション構成ファイルを Configuration オブジェクトとして開きます。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

WebConfigurationManager クラス
System.Web.Configuration 名前空間
Configuration
ConfigurationManager

その他の技術情報

ASP.NET 構成の概要

WebConfigurationManager メンバ

Web アプリケーションに適用される構成ファイルにアクセスできるようにします。

WebConfigurationManager データ型で公開されるメンバを以下の表に示します。


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ AppSettings 現在の Web アプリケーションの既定の構成の AppSettingsSection データを取得します。
パブリック プロパティ ConnectionStrings 現在の Web アプリケーションの既定の構成の ConnectionStringsSection データを取得します。
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetSection オーバーロードされます。 現在の Web アプリケーションの既定の構成ファイルの、指定した構成セクションを取得します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド GetWebApplicationSection 現在の Web アプリケーションの構成ファイルの、指定した構成セクションを取得します。
パブリック メソッド OpenMachineConfiguration オーバーロードされます。 マシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
パブリック メソッド OpenMappedMachineConfiguration オーバーロードされます。 マシン構成ファイルを Configuration として開き、読み取りまたは書き込みができるようにします。
パブリック メソッド OpenMappedWebConfiguration オーバーロードされます。 指定したファイル マップを使用して、Web アプリケーション構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
パブリック メソッド OpenWebConfiguration オーバーロードされます。 Web アプリケーション構成ファイルを Configuration オブジェクトとして開きます。
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

WebConfigurationManager クラス
System.Web.Configuration 名前空間
Configuration
ConfigurationManager

その他の技術情報

ASP.NET 構成の概要



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「WebConfigurationManager」の関連用語

WebConfigurationManagerのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebConfigurationManagerのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS