WebConfigurationManager クラス
アセンブリ: System.Web (system.web.dll 内)
構文
解説WebConfigurationManager を使用すると、マシン情報やアプリケーション情報にアクセスできます。
Web アプリケーション関連の構成ファイルを処理する場合は、WebConfigurationManager の使用をお勧めします。クライアント アプリケーションの場合は、ConfigurationManager を使用します。
次に説明するように、作成したアプリケーションで System.Configuration 型を拡張したり、それを直接使用して構成情報を処理したりできます。
-
構成の処理。標準型を使用して構成情報を処理するには、次のいずれかの方法を使用します。
-
セクションへのアクセス。アプリケーションの構成情報にアクセスするには、WebConfigurationManager によって提供された GetSection メソッドのいずれかを使用する必要があります。appSettings と connectionStrings の場合は、AppSettings プロパティと ConnectionStrings プロパティを使用します。これらのメソッドは、読み取り専用の操作を実行し、構成のキャッシュされた 1 つのインスタンスを使用し、マルチスレッド対応です。
-
構成ファイルへのアクセス。アプリケーションは、そのアプリケーション自体や他のアプリケーション、またはコンピュータのあらゆるレベルで、ローカルまたはリモートから構成設定の読み取りと書き込みを行うことができます。WebConfigurationManager によって提供された open メソッドの 1 つを使用します。これらのメソッドは、Configuration オブジェクトを返します。このオブジェクトにより、基になる構成ファイルを処理するために必要なメソッドとプロパティが提供されます。これらのメソッドは、読み取り操作または書き込み操作を実行し、ファイルが開かれるたびに構成データを再作成します。
-
詳細な構成。より詳細な構成処理は、SectionInformation、PropertyInformation、PropertyInformationCollection、ElementInformation、ContextInformation、ConfigurationSectionGroup、ConfigurationSectionGroupCollection、および WebConfigurationSectionGroup の各型によって提供されます。
-
-
構成の標準型の拡張。ConfigurationElement、ConfigurationElementCollection、ConfigurationProperty、および ConfigurationSection などの標準の構成を、プログラムや属性モデルを使用して拡張して、カスタム構成要素を提供することもできます。構成の標準型をプログラムを使用して拡張する方法の例については、ConfigurationSection のトピックを参照してください。構成の標準型を属性モデルを使用して拡張する方法の例については、ConfigurationElement のトピックを参照してください。
メモ |
|---|
| パス パラメータを受け取る静的な 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.Web.Configuration.WebConfigurationManager
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照WebConfigurationManager メンバ
System.Web.Configuration 名前空間
Configuration
ConfigurationManager
その他の技術情報
ASP.NET 構成の概要
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 から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( 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 から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
参照関連項目
WebConfigurationManager クラスSystem.Web.Configuration 名前空間
Configuration
ConfigurationManager
その他の技術情報
ASP.NET 構成の概要- WebConfigurationManagerのページへのリンク
.gif)