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

Configuration クラス

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

特定のコンピュータアプリケーション、またはリソース適用できる構成ファイル表します。このクラス継承できません。

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

Public NotInheritable Class
 Configuration
Dim instance As Configuration
public sealed class Configuration
public ref class Configuration sealed
public final class Configuration
public final class Configuration
解説解説

Configuration クラス インスタンスは、特定の物理エンティティ (コンピュータなど) または論理エンティティ (アプリケーションWeb サイトなど) に適用される構成設定マージされたビュー表します指定され論理エンティティは、ローカル コンピュータまたはリモート サーバー存在することがあります

指定したエンティティ用の構成ファイル存在しない場合Configuration オブジェクトは、Machine.config ファイル定義されている既定構成設定表します

次のクラス定義されている、構成オープン メソッド1 つ使用してConfiguration オブジェクト取得できます

指定したエンティティ用の継承され構成設定を表す構成ファイル生成するには、構成保存メソッド1 つ使用します

メモメモ

リモート コンピュータ上の構成設定アクセスできるようにするには、Aspnet_regiis コマンドライン ツール使用します。このツール詳細については、「ASP.NET IIS 登録ツール (Aspnet_regiis.exe)」を参照してください.NET Framework含まれている組み込みセクション以外のカスタム構成設定作成およびアクセス詳細については、ConfigurationSection のトピック参照してください

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

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

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

使用例使用例

Configuration クラス使用してカスタム セクション含まれている構成ファイル作成する方法次のコード例示します

' Create a custom section.
Shared Sub CreateSection() 
    Try
        
        Dim customSection As CustomSection
        
        ' Get the current configuration file.
        Dim config As _
        System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)
        
        ' Create the section entry  
        ' in <configSections> and the 
        ' related target section in <configuration>.
        If config.Sections("CustomSection")
 Is Nothing Then
            customSection = New CustomSection()
            config.Sections.Add("CustomSection", customSection)
            customSection.SectionInformation.ForceSave = True
            config.Save(ConfigurationSaveMode.Full)
            
            Console.WriteLine( _
            "Section name: {0} created", _
            customSection.SectionInformation.Name)
        End If
    
    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try

End Sub 'CreateSection
 
       
// Create a custom section.
static void CreateSection()
{
    try
    {

        CustomSection customSection;

        // Get the current configuration file.
        System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

        // Create the section entry  
        // in <configSections> and the 
        // related target section in <configuration>.
        if (config.Sections["CustomSection"] == null)
        {
            customSection = new CustomSection();
            config.Sections.Add("CustomSection", customSection);
            customSection.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Full);

            Console.WriteLine("Section name: {0} created",
                customSection.SectionInformation.Name);

        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }

}

前述の例で使用されているカスタム セクションの定義を次に示します

' Define a custom section.

NotInheritable Public Class
 CustomSection
    Inherits ConfigurationSection
    
    
    Public Enum Permissions
        FullControl = 0
        Modify = 1
        ReadExecute = 2
        Read = 3
        Write = 4
        SpecialPermissions = 5
    End Enum 'Permissions
    
    
    Public Sub New() 
    
    End Sub 'New
    
    
    
    <ConfigurationProperty("fileName", _
    DefaultValue:="default.txt"), _
    StringValidator(InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\",
 _
    MinLength:=1, MaxLength:=60)> _
    Public Property FileName() As
 String
        Get
            Return CStr(Me("fileName"))
        End Get
        Set(ByVal value As
 String)
            Me("fileName") = Value
        End Set
    End Property
    
    
    <ConfigurationProperty("maxIdleTime", _
    DefaultValue:="1:30:30")> _
    Public Property MaxIdleTime() As
 TimeSpan
        Get
            Return CType(Me("maxIdleTime"),
 TimeSpan)
        End Get
        Set(ByVal value As
 TimeSpan)
            Me("maxIdleTime") =
 Value
        End Set
    End Property
    
    
    
    <ConfigurationProperty("permission", _
    DefaultValue:=Permissions.Read)> _
    Public Property Permission() As
 Permissions
        Get
            Return CType(Me("permission"),
 Permissions)
        End Get

        Set(ByVal value As
 Permissions)
            Me("permission") =
 Value
        End Set
    End Property
End Class 'CustomSection

// Define a custom section.
public sealed class CustomSection :
    ConfigurationSection
{

    public enum Permissions
    {
        FullControl = 0,
        Modify = 1,
        ReadExecute = 2,
        Read = 3,
        Write = 4,
        SpecialPermissions = 5
    }

    public CustomSection()
    {

    }

    [ConfigurationProperty("fileName", 
        DefaultValue = "default.txt")]
    [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\"
,
               MinLength = 1, MaxLength = 60)]
    public String FileName
    {
        get
        {
            return (String)this["fileName"];
        }
        set
        {
            this["fileName"] = value;
        }
    }
   
    [ConfigurationProperty("maxIdleTime", DefaultValue="1:30:30")]
    public TimeSpan MaxIdleTime
    {
        get
        {
            return (TimeSpan)this["maxIdleTime"];
        }
        set
        {
            this["maxIdleTime"] = value;
        }
    }
    

    [ConfigurationProperty("permission", 
        DefaultValue = Permissions.Read)]
    public Permissions Permission
    {
        get
        {
            return (Permissions)this["permission"];
        }

        set
        {
            this["permission"] = value;
        }

    }
  
}

前述の例で使用されている構成抜粋次に示します

<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <configSections>
    <section name="CustomSection" type="Samples.AspNet.CustomSection, 
      Configuration, Version=1.0.0.0, Culture=neutral, 
      PublicKeyToken=null" allowDefinition="Everywhere" 
      allowExeDefinition="MachineToApplication" 
      restartOnExternalChanges="true" />
  </configSections>
    <CustomSection fileName="default.txt" maxIdleTime="01:30:30"
      permission="Read" />

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

Configuration プロパティ


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

  名前 説明
パブリック プロパティ AppSettings この Configuration オブジェクト適用される AppSettingsSection オブジェクトの構成セクション取得します
パブリック プロパティ ConnectionStrings この Configuration オブジェクト適用される ConnectionStringsSection 構成セクション オブジェクト取得します
パブリック プロパティ EvaluationContext Configuration オブジェクトの ContextInformation オブジェクト取得します
パブリック プロパティ FilePath この Configuration オブジェクトによって表される構成ファイルへの物理パス取得します
パブリック プロパティ HasFile この Configuration オブジェクトによって表されるリソース用の構成ファイルがあるかどうか示します
パブリック プロパティ Locations この Configuration オブジェクト内で定義されている位置取得します
パブリック プロパティ NamespaceDeclared 構成ファイルXML 名前空間があるかどうかを示す値を取得または設定します
パブリック プロパティ RootSectionGroup この Configuration オブジェクトルート ConfigurationSectionGroup を取得します
パブリック プロパティ SectionGroups この構成定義されているセクション グループコレクション取得します
パブリック プロパティ Sections この構成定義されているセクションコレクション取得します
参照参照

関連項目

Configuration クラス
System.Configuration 名前空間
ConfigurationSection

その他の技術情報

ASP.NET アプリケーション構成

Configuration メソッド


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

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

Configuration クラス
System.Configuration 名前空間
ConfigurationSection

その他の技術情報

ASP.NET アプリケーション構成

Configuration メンバ

特定のコンピュータアプリケーション、またはリソース適用できる構成ファイル表します。このクラス継承できません。

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


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ AppSettings この Configuration オブジェクト適用される AppSettingsSection オブジェクトの構成セクション取得します
パブリック プロパティ ConnectionStrings この Configuration オブジェクト適用される ConnectionStringsSection 構成セクション オブジェクト取得します
パブリック プロパティ EvaluationContext Configuration オブジェクトの ContextInformation オブジェクト取得します
パブリック プロパティ FilePath この Configuration オブジェクトによって表される構成ファイルへの物理パス取得します
パブリック プロパティ HasFile この Configuration オブジェクトによって表されるリソース用の構成ファイルがあるかどうか示します
パブリック プロパティ Locations この Configuration オブジェクト内で定義されている位置取得します
パブリック プロパティ NamespaceDeclared 構成ファイルXML 名前空間があるかどうかを示す値を取得または設定します
パブリック プロパティ RootSectionGroup この Configuration オブジェクトルート ConfigurationSectionGroup取得します
パブリック プロパティ SectionGroups この構成定義されているセクション グループコレクション取得します
パブリック プロパティ Sections この構成定義されているセクションコレクション取得します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

Configuration クラス
System.Configuration 名前空間
ConfigurationSection

その他の技術情報

ASP.NET アプリケーション構成


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

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

辞書ショートカット

すべての辞書の索引

「Configuration」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS