WebConfigurationManager::GetSection Method (String^, String^)
Retrieves the specified configuration section from the Web application's configuration file at the specified location.
Assembly: System.Web (in System.Web.dll)
Parameters
- sectionName
-
Type:
System::String^
The configuration section name.
- path
-
Type:
System::String^
The virtual configuration file path.
Return Value
Type: System::Object^The specified configuration section object, or null if the section does not exist. Remember that security restrictions exist on the use of GetSection as a run-time operation. You might not be able to access a section at run time for modifications, for instance.
| Exception | Condition |
|---|---|
| InvalidOperationException | The method is called from outside a Web application. |
| ConfigurationErrorsException | A valid configuration file could not be loaded. |
If GetSection is called from within a Web application, it gets the section from the configuration file defined by the specified path in the configuration hierarchy.
Caution |
|---|
If your application uses a different protocol than HTTP, the GetSection overload that takes both a section name and a path in its parameter list is the one to use. You must specify the configuration file path because the system cannot make any assumptions about the configuration hierarchy level. If you use the GetSection overload that takes only a section name, the system will always attempt to return the configuration settings at the application level. Note, though, that if its specified path is outside of the current application, the overload that takes a path will also return the application-level configuration settings for the currently running application. |
This method cannot be called from within a client application.
If you want to retrieve the configuration section from the configuration file located at the current Web application directory level, use the GetSection method.
Note |
|---|
The GetSection method is a run-time method operating on the section of a configuration file at the hierarchy level in which the application runs. For a non-run-time operation, use GetSection instead. This method operates on the specified section of a configuration file that you obtain using one of the open configuration file methods. |
Notes to Implementers:
The return value must be cast to the expected configuration type before use. To avoid possible casting exceptions, you should use a conditional casting operation like the as operator in C# or the function in Visual Basic.
The following example shows how to access configuration information with the GetSection method.
Note |
|---|
This example demonstrates how to use the GetSection method to get a ConfigurationSection object from a specified configuration file. |
Available since 2.0

