This documentation is archived and is not being maintained.

WebConfigurationManager.GetWebApplicationSection Method

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

Namespace:  System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)

public static Object GetWebApplicationSection(
	string sectionName


Type: System.String
The configuration section name.

Return Value

Type: System.Object
The specified configuration section object, or null if the section does not exist, or an internal object if the section is not accessible at run time.


A valid configuration file could not be loaded.

If GetWebApplicationSection is called from within a Web application, it gets the section from the configuration file selected by the system according to the Web-application configuration hierarchy.

You could call GetWebApplicationSection from within a client application. In this case, it gets the default section from the configuration file selected by the system according to the client configuration hierarchy. Usually, this is the Machine.config file, unless you have a mapped configuration in place. For mapping configuration files, refer to the mapping methods described next.


The GetWebApplicationSection method is a run-time operation that acts on the section of the application configuration file located at the current level. The GetSection method, however, is not a run-time operation but acts on the specified section obtained through one of the methods for opening the configuration files.

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 TryCast function in Visual Basic.

The following example shows how to access configuration information with the GetWebApplicationSection method.


This example demonstrates how to use the GetWebApplicationSection method to get a ConfigurationSection object from the default configuration file.

       // Show the use of GetWebApplicationSection(string). 
       // to get the connectionStrings section.
        static void GetWebApplicationSection()

            // Get the default connectionStrings section,
            ConnectionStringsSection connectionStringsSection =
                "connectionStrings") as ConnectionStringsSection;

            // Get the connectionStrings key,value pairs collection.
            ConnectionStringSettingsCollection connectionStrings =

            // Get the collection enumerator.
            IEnumerator connectionStringsEnum =

            // Loop through the collection and 
            // display the connectionStrings key, value pairs.
            int i = 0;
            Console.WriteLine("[Display connectionStrings]");
            while (connectionStringsEnum.MoveNext())
                string name = connectionStrings[i].Name;
                Console.WriteLine("Name: {0} Value: {1}",
                name, connectionStrings[name]);
                i += 1;


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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