Configuration クラス
アセンブリ: System.Configuration (system.configuration.dll 内)

Public NotInheritable Class Configuration

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 クラスのページへのリンク