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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > 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) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「WebConfigurationManager クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS