WebConfigurationManager.GetSection Method

Definition

Retrieves the specified configuration section from the current application's default configuration file.

Overloads

GetSection(String)

Retrieves the specified configuration section from the current application's configuration file.

GetSection(HttpContext, String)

Retrieves the specified configuration section from the application's configuration file in relationship to the specified context.

GetSection(String, String, String)

Retrieves the specified configuration section by using the Web site name, virtual path, and section path.

GetSection(HttpContext, String, Type)

Retrieves the specified configuration section by using the specified configuration section type from the application's configuration file in relationship to the specified context.

GetSection(String, String, String, Type)

Retrieves the specified configuration section by using the Web site name, virtual path, section path, and run-time type.

GetSection(String)

Retrieves the specified configuration section from the current application's configuration file.

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::String ^ sectionPath);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (string sectionPath);
static member GetSection : string -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (sectionPath As String) As ConfigurationSection

Parameters

sectionPath
String

The configuration section name.

Returns

The specified configuration section object, or null if the section does not exist.

Exceptions

A valid configuration file cannot be loaded.

Remarks

If the GetSection(String) overload is called from within a Web application, it returns the section from the configuration file that is selected by the system according to the configuration hierarchy of the Web application.

Caution

If your application uses a protocol other than HTTP, you need to use the GetSection(HttpContext, String) or GetSection(String, String, String, Type) overload, which each take both a section name and an System.Web.HttpContext object in their parameter list. You must specify the HttpContext to enable the system to return the configuration settings at a particular configuration hierarchy level. However, if the specified configuration path is outside of the current application, GetSection and GetSection(String, String, String, Type) will return the application-level configuration settings for the currently running application. If you use GetSection(String), which takes only a section name, the system will always attempt to return the configuration settings at the application level.

Important

The use of GetSection(String) as a run-time operation is limited by security restrictions. For example, you might not be able to access or modify a section at run time.

Applies to

GetSection(HttpContext, String)

Retrieves the specified configuration section from the application's configuration file in relationship to the specified context.

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::Web::HttpContext ^ context, System::String ^ sectionPath);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (System.Web.HttpContext context, string sectionPath);
static member GetSection : System.Web.HttpContext * string -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (context As HttpContext, sectionPath As String) As ConfigurationSection

Parameters

context
HttpContext

The HttpContext of the current request.

sectionPath
String

The configuration section name.

Returns

The specified configuration section object, or null if the section does not exist.

Exceptions

A valid configuration file cannot be loaded.

Remarks

If the GetSection(HttpContext, String) overload is called from within a Web application, it returns the section from the configuration file that is selected by the system according to the System.Web.HttpContext object of the Web application.

Caution

If your application uses a protocol other than HTTP, you need to use the GetSection(HttpContext, String) or GetSection(String, String, String, Type) overload, which each take both a section name and an HttpContext in their parameter list. You must specify the HttpContext to enable the system to return the configuration settings at a particular configuration hierarchy level. However, if the specified configuration path is outside of the current application, GetSection(HttpContext, String) and GetSection(String, String, String, Type) will return the application-level configuration settings for the currently running application. If you use the GetSection(String) overload, which takes only a section name, the system will always attempt to return the configuration settings at the application level.

Important

The use of GetSection(HttpContext, String) as a run-time operation is limited by security restrictions. For example, you might not be able to access or modify a section at run time.

Applies to

GetSection(String, String, String)

Retrieves the specified configuration section by using the Web site name, virtual path, and section path.

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::String ^ siteName, System::String ^ virtualPath, System::String ^ sectionPath);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (string siteName, string virtualPath, string sectionPath);
static member GetSection : string * string * string -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (siteName As String, virtualPath As String, sectionPath As String) As ConfigurationSection

Parameters

siteName
String

The name of the Web site.

virtualPath
String

The virtual path of the Web.config file.

sectionPath
String

The configuration section name.

Returns

A ConfigurationSection object.

Exceptions

A valid configuration file cannot be loaded.

One of the parameters passed to the method is null.

Remarks

The GetSection(String, String, String) overload returns a ConfigurationSection object that represents the configuration for the requested location. This method first finds the Web site requested in the siteName parameter and then finds the Web.config file in the specified virtualPath. GetSection(String, String, String) then searches the Web.config file for the requested configuration sectionPath.

Important The use of GetSection(String, String, String) as a run-time operation is limited by security restrictions. For example, you might not be able to access or modify a section at run time

Applies to

GetSection(HttpContext, String, Type)

Retrieves the specified configuration section by using the specified configuration section type from the application's configuration file in relationship to the specified context.

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::Web::HttpContext ^ context, System::String ^ sectionPath, Type ^ sectionType);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (System.Web.HttpContext context, string sectionPath, Type sectionType);
static member GetSection : System.Web.HttpContext * string * Type -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (context As HttpContext, sectionPath As String, sectionType As Type) As ConfigurationSection

Parameters

context
HttpContext

The HttpContext object of the current request.

sectionPath
String

The configuration section name.

sectionType
Type

The configuration section type

Returns

The specified configuration section object, or null if the section does not exist.

Exceptions

A valid configuration file cannot be loaded.

One of the parameters passed to the method is null.

The value of the sectionType parameter does not derive from the ConfigurationSection class or does not provide a public constructor.

Remarks

If the GetSection(HttpContext, String, Type) overload is called from within a Web application, it returns the section from the configuration file that is selected by the system according to the System.Web.HttpContext object of the Web application as well as the sectionPath and sectionType parameters provided.

Caution

If your application uses a protocol other than HTTP, you need to use the GetSection(HttpContext, String) or GetSection(String, String, String, Type) overload, which each take both a section name and an HttpContext in their parameter list. You must specify the HttpContext to enable the system to return the configuration settings at a particular configuration hierarchy level. However, if the specified configuration path is outside of the current application, GetSection(HttpContext, String) and GetSection(String, String, String, Type) will return the application-level configuration settings for the currently running application. If you use the GetSection(String) overload, which takes only a section name, the system will always attempt to return the configuration settings at the application level.

Important

The use of GetSection(HttpContext, String, Type) as a run-time operation is limited by security restrictions. For example, you might not be able to access or modify a section at run time.

Applies to

GetSection(String, String, String, Type)

Retrieves the specified configuration section by using the Web site name, virtual path, section path, and run-time type.

public:
 static Microsoft::Web::Administration::ConfigurationSection ^ GetSection(System::String ^ siteName, System::String ^ virtualPath, System::String ^ sectionPath, Type ^ sectionType);
public static Microsoft.Web.Administration.ConfigurationSection GetSection (string siteName, string virtualPath, string sectionPath, Type sectionType);
static member GetSection : string * string * string * Type -> Microsoft.Web.Administration.ConfigurationSection
Public Shared Function GetSection (siteName As String, virtualPath As String, sectionPath As String, sectionType As Type) As ConfigurationSection

Parameters

siteName
String

The name of the Web site.

virtualPath
String

The virtual path of the Web.config file.

sectionPath
String

The configuration section name.

sectionType
Type

The run-time type of the configuration section.

Returns

A ConfigurationSection object.

Remarks

The GetSection(String, String, String, Type) overload returns a ConfigurationSection object that represents the configuration for the requested location. This method first finds the Web site requested in the siteName parameter and then finds the Web.config file in the specified virtualPath. GetSection(String, String, String, Type) then searches the Web.config file for the requested configuration sectionPath that matches the run-time type provided in the sectionType parameter.

Important

The use of GetSection(String, String, String, Type) as a run-time operation is limited by security restrictions. For example, you might not be able to access or modify a section at run time.

Applies to