Export (0) Print
Expand All
0 out of 4 rated this helpful - Rate this topic

Configuration Class

Represents a configuration file that is applicable to a particular computer, application, or resource. This class cannot be inherited.

System.Object
  System.Configuration.Configuration

Namespace:  System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)
[<Sealed>]
type Configuration =  class end

The Configuration type exposes the following members.

  NameDescription
Public propertyAppSettingsGets the AppSettingsSection object configuration section that applies to this Configuration object.
Public propertyAssemblyStringTransformerSpecifies a function delegate that is used to transform assembly strings in configuration files.
Public propertyConnectionStringsGets a ConnectionStringsSection configuration-section object that applies to this Configuration object.
Public propertyEvaluationContextGets the ContextInformation object for the Configuration object.
Public propertyFilePathGets the physical path to the configuration file represented by this Configuration object.
Public propertyHasFileGets a value that indicates whether a file exists for the resource represented by this Configuration object.
Public propertyLocationsGets the locations defined within this Configuration object.
Public propertyNamespaceDeclaredGets or sets a value indicating whether the configuration file has an XML namespace.
Public propertyRootSectionGroupGets the root ConfigurationSectionGroup for this Configuration object.
Public propertySectionGroupsGets a collection of the section groups defined by this configuration.
Public propertySectionsGets a collection of the sections defined by this Configuration object.
Public propertyTargetFrameworkSpecifies the targeted version of the .NET Framework when a version earlier than the current one is targeted.
Public propertyTypeStringTransformerSpecifies a function delegate that is used to transform type strings in configuration files.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetSectionReturns the specified ConfigurationSection object.
Public methodGetSectionGroupGets the specified ConfigurationSectionGroup object.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSave()Writes the configuration settings contained within this Configuration object to the current XML configuration file.
Public methodSave(ConfigurationSaveMode)Writes the configuration settings contained within this Configuration object to the current XML configuration file.
Public methodSave(ConfigurationSaveMode, Boolean)Writes the configuration settings contained within this Configuration object to the current XML configuration file.
Public methodSaveAs(String)Writes the configuration settings contained within this Configuration object to the specified XML configuration file.
Public methodSaveAs(String, ConfigurationSaveMode)Writes the configuration settings contained within this Configuration object to the specified XML configuration file.
Public methodSaveAs(String, ConfigurationSaveMode, Boolean)Writes the configuration settings contained within this Configuration object to the specified XML configuration file.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Configuration settings are stored in a hierarchy of configuration files. The Configuration class instance represents the merged view of the configuration settings from all of the configuration files that apply to a specific physical entity, such as a computer, or to a logical entity, such as an application or a Web site. The logical entity can exist on the local computer or on a remote server. For information about configuration files, see Configuration Files and ASP.NET Configuration Files.

When no configuration file exists for a specified entity, the Configuration object represents the default configuration settings as defined by the Machine.config file.

You can get a Configuration object by using the following classes:

The names of the methods that return a Configuration object begin with "Open".

You can also generate a configuration file that represents the configuration settings in a Configuration object. To do this, use one of the following methods:

  • Call the Save method to create a new configuration file.

  • Call the SaveAs method to generate a new configuration file at another location.

The names of the methods that create configuration files begin with "Save".

NoteNote

To enable access to configuration settings on a remote computer, use the Aspnet_regiis command-line tool. For more information about this tool, see ASP.NET IIS Registration Tool (Aspnet_regiis.exe). For information about creating and accessing custom configuration settings other than the intrinsic sections included in the .NET Framework, refer to ConfigurationSection.

Notes to Implementers

The Configuration class provides programmatic access for editing configuration files. You use one of the "Open" methods provided by the WebConfigurationManager class for Web applications or by the ConfigurationManager class for client applications. These methods return a Configuration object, which in turn provides the methods and properties that handle the underlying configuration files. You can access these files for reading or writing configuration information.

You use the GetSection method or the GetSectionGroup method to read configuration information. Note that the user or process that reads must have the following permissions:

  • Read permission on the configuration file at the current configuration hierarchy level.

  • Read permissions on all the parent configuration files.

If your application needs read-only access to its own configuration, it is recommended that you use the GetSection method overloads for Web applications. For client application, use the GetSection method.

These methods provide access to the cached configuration values for the current application, which has better performance than the Configuration class.

NoteNote

If you use a static GetSection method that takes a path parameter, the path parameter must refer to the application in which the code is running, otherwise the parameter is ignored and configuration information for the currently running application is returned.

You use one of the Save methods to write configuration information. Note that the user or process that writes must have the following permissions:

  • Write permission on the configuration file and directory at the current configuration hierarchy level.

  • Read permissions on all the configuration files.

The following code example demonstrates how to use the Configuration class to access configuration file elements.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.