Freigeben über


How to: View Inherited and Local Configuration Settings Programmatically

Because each ASP.NET application inherits default configuration settings from the root Web.config file, you need to create Web.config files only for settings that override the default settings. If there are other Web.config files in the hierarchy, you might not know what default settings are inherited by your application, and therefore you might not know what to override.

This example uses the non-static method of obtaining configuration data, which allows you to pull configuration information from any application. If you are going to obtain configuration information from the application in which your code resides, use the static method, which processes faster. For more information, see the Working with Local and Remote Configuration Settings section in ASP.NET Configuration API Overview.

Example

The following code example gets all of the configuration settings for an ASP.NET application called MyApp in the Default Web Site, and then writes the settings to an XML file.

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Management
Imports System.Configuration
Imports System.Web.Configuration

Namespace SamplesAspNet.Config

    Class GetFullConfig

        Public Shared Sub Main(ByVal args() As String)
            Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("/MyApp")
            config.SaveAs("c:\MyApp.web.config", ConfigurationSaveMode.Full, True)
        End Sub 'Main 

    End Class 

End Namespace
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web.Configuration;

namespace SamplesAspNet.Config
{
    class GetFullConfig
    {
        public static void Main(string[] args)
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration("/MyApp");
            config.SaveAs("c:\\MyApp.web.config", ConfigurationSaveMode.Full, true);
        }
    }
}

Compiling the Code

See Also

Concepts

Configuration How-to Topics

Reference

OpenWebConfiguration

SaveAs

Other Resources

Administering ASP.NET Web Sites