Configuration クラス
アセンブリ: System.Configuration (system.configuration.dll 内)
構文
解説
Configuration クラス インスタンスは、特定の物理エンティティ (コンピュータなど) または論理エンティティ (アプリケーションや Web サイトなど) に適用される構成設定のマージされたビューを表します。指定された論理エンティティは、ローカル コンピュータまたはリモート サーバーに存在することがあります。
指定したエンティティ用の構成ファイルが存在しない場合、Configuration オブジェクトは、Machine.config ファイルで定義されている既定の構成設定を表します。
次のクラスで定義されている、構成のオープン メソッドの 1 つを使用して、Configuration オブジェクトを取得できます。
指定したエンティティ用の継承された構成設定を表す構成ファイルを生成するには、構成の保存メソッドの 1 つを使用します。
メモ |
---|
リモート コンピュータ上の構成設定にアクセスできるようにするには、Aspnet_regiis コマンドライン ツールを使用します。このツールの詳細については、「ASP.NET IIS 登録ツール (Aspnet_regiis.exe)」を参照してください。.NET Framework に含まれている組み込みセクション以外のカスタム構成設定の作成およびアクセスの詳細については、ConfigurationSection のトピックを参照してください。 |
メモ |
---|
パス パラメータを受け取る静的な GetSection メソッドを使用する場合、パス パラメータは、コードを実行しているアプリケーションを参照している必要があります。そうでない場合は、パラメータが無視され、現在実行中のアプリケーションの構成情報が返されます。 |
Topic | Location |
---|---|
方法 : SqlDataSource コントロールを使用して Oracle データベースに接続する | ASP .NET Web アプリケーションの作成 |
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.Configuration.Configuration
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Configuration プロパティ
パブリック プロパティ
名前 | 説明 | |
---|---|---|
AppSettings | この Configuration オブジェクトに適用される AppSettingsSection オブジェクトの構成セクションを取得します。 | |
ConnectionStrings | この Configuration オブジェクトに適用される ConnectionStringsSection 構成セクション オブジェクトを取得します。 | |
EvaluationContext | Configuration オブジェクトの ContextInformation オブジェクトを取得します。 | |
FilePath | この Configuration オブジェクトによって表される構成ファイルへの物理パスを取得します。 | |
HasFile | この Configuration オブジェクトによって表されるリソース用の構成ファイルがあるかどうかを示します。 | |
Locations | この Configuration オブジェクト内で定義されている位置を取得します。 | |
NamespaceDeclared | 構成ファイルに XML 名前空間があるかどうかを示す値を取得または設定します。 | |
RootSectionGroup | この Configuration オブジェクトのルート ConfigurationSectionGroup を取得します。 | |
SectionGroups | この構成で定義されているセクション グループのコレクションを取得します。 | |
Sections | この構成で定義されているセクションのコレクションを取得します。 |
Configuration メソッド
パブリック メソッド
名前 | 説明 | |
---|---|---|
Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) | |
GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) | |
GetSection | 指定した ConfigurationSection オブジェクトを返します。 | |
GetSectionGroup | 指定した ConfigurationSectionGroup オブジェクトを取得します。 | |
GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) | |
ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) | |
Save | オーバーロードされます。 この Configuration オブジェクトに格納されている構成設定を、現在の XML 構成ファイルに書き込みます。 | |
SaveAs | オーバーロードされます。 この Configuration オブジェクトに格納されている構成設定を、指定された XML 構成ファイルに書き込みます。 | |
ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
名前 | 説明 | |
---|---|---|
Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) | |
MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
Configuration メンバ
特定のコンピュータ、アプリケーション、またはリソースに適用できる構成ファイルを表します。このクラスは継承できません。
Configuration データ型で公開されるメンバを以下の表に示します。
パブリック プロパティ
名前 | 説明 | |
---|---|---|
AppSettings | この Configuration オブジェクトに適用される AppSettingsSection オブジェクトの構成セクションを取得します。 | |
ConnectionStrings | この Configuration オブジェクトに適用される ConnectionStringsSection 構成セクション オブジェクトを取得します。 | |
EvaluationContext | Configuration オブジェクトの ContextInformation オブジェクトを取得します。 | |
FilePath | この Configuration オブジェクトによって表される構成ファイルへの物理パスを取得します。 | |
HasFile | この Configuration オブジェクトによって表されるリソース用の構成ファイルがあるかどうかを示します。 | |
Locations | この Configuration オブジェクト内で定義されている位置を取得します。 | |
NamespaceDeclared | 構成ファイルに XML 名前空間があるかどうかを示す値を取得または設定します。 | |
RootSectionGroup | この Configuration オブジェクトのルート ConfigurationSectionGroup を取得します。 | |
SectionGroups | この構成で定義されているセクション グループのコレクションを取得します。 | |
Sections | この構成で定義されているセクションのコレクションを取得します。 |
名前 | 説明 | |
---|---|---|
Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) | |
GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) | |
GetSection | 指定した ConfigurationSection オブジェクトを返します。 | |
GetSectionGroup | 指定した ConfigurationSectionGroup オブジェクトを取得します。 | |
GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) | |
ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) | |
Save | オーバーロードされます。 この Configuration オブジェクトに格納されている構成設定を、現在の XML 構成ファイルに書き込みます。 | |
SaveAs | オーバーロードされます。 この Configuration オブジェクトに格納されている構成設定を、指定された XML 構成ファイルに書き込みます。 | |
ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
名前 | 説明 | |
---|---|---|
Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) | |
MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
Weblioに収録されているすべての辞書からConfigurationを検索する場合は、下記のリンクをクリックしてください。
全ての辞書からConfigurationを検索
- Configurationのページへのリンク