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

ConfigurationManager クラス

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

クライアント アプリケーション構成ファイルアクセスできるようにします。このクラス継承できません。

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

解説解説

ConfigurationManager クラス使用すると、マシン構成情報アプリケーション構成情報、およびユーザー構成情報アクセスできます。このクラスは ConfigurationSettings クラス代わるもので、優先して使用されます。

クライアント アプリケーションクライアント コンピュータ実行されWeb アプリケーションクライアント接続先であるサーバー コンピュータ実行されます。

System.Configuration組み込みの型またはこれらの型から派生した型を使用して構成情報を処理できます。これらの型を使用すると、構成情報直接処理することが可能で、構成ファイル拡張してカスタム情報含めることもできます

ConfigurationManager クラスには、次のタスク実行できるメンバ含まれています。

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

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

ConfigurationManager クラス使用してカスタム構成セクションアクセスする方法次のコード例示しますセクション存在しない場合は、セクション作成され構成ファイル追加されます。この例で使用するカスタム セクション クラスは、ConfigurationPropertyAttribute クラス含まれる例で実装されます

 ' Create a custom section.
Shared Sub New()
   ' Get the application configuration file.
     Dim config As System.Configuration.Configuration
 = _
     ConfigurationManager.OpenExeConfiguration( _
     ConfigurationUserLevel.None)
   ' Console.WriteLine(config.FilePath);
   ' If the section does not exiat in the configuration
   ' file, create it and save it to the file.
   If config.Sections(customSectionName) Is
 Nothing Then
      custSection = New CustomSection()
      config.Sections.Add(customSectionName, custSection)
      custSection = config.GetSection(customSectionName)
      custSection.SectionInformation.ForceSave = True
      config.Save(ConfigurationSaveMode.Full)
   End If
End Sub 'New

// Create a custom section.
static UsingConfigurationManager()
{
    // Get the application configuration file.
    System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);
 
    // If the section does not exist in the configuration
    // file, create it and save it to the file.
    if (config.Sections[customSectionName] == null)
    {
        custSection = new CustomSection();
        config.Sections.Add(customSectionName, custSection);
        custSection =
            config.GetSection(customSectionName) as CustomSection;
        custSection.SectionInformation.ForceSave = true;
        config.Save(ConfigurationSaveMode.Full);
    }
}

この例では、次の構成ファイル示される要素処理します。この構成ファイルは、このコード例初め実行したときに生成されます。

メモメモ

バージョン管理要件反映するには、Version 属性設定する必要があります

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="CustomSection" 
       type="Samples.Config.CustomSection,
         ConfigurationManager, 
         Version=1.0.0.0, 
         Culture=neutralPublicKeyToken=null" 
         allowDefinition="Everywhere" 
         allowExeDefinition="MachineToApplication" 
         restartOnExternalChanges="true" />
  </configSections>
  <connectionStrings>
    <add name="ConnStr1" 
      connectionString="LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;Initial
 Catalog=aspnetdb"
      providerName="System.Data.SqlClient" />
    <add name="ConnStr2" 
      connectionString="LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;Initial
 Catalog=aspnetdb"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="AppSetting0" 
      value="Monday, February 28, 2005 1:27:59 PM" />
    <add key="AppSetting1" 
      value="Monday, February 28, 2005 1:36:40 PM" />
  </appSettings>
  <CustomSection fileName="default.txt" maxUsers="1000" 
     maxIdleTime="00:10:00" />
</configuration>
継承階層継承階層
System.Object
  System.Configuration.ConfigurationManager
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からConfigurationManager クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConfigurationManager クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConfigurationManager クラス を検索

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

辞書ショートカット

すべての辞書の索引

「ConfigurationManager クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS