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 構成概要



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「WebConfigurationManager」の関連用語

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

   

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



WebConfigurationManagerのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS