방법: 상속된 구성 설정과 로컬 구성 설정을 프로그래밍 방식으로 보기

업데이트: 2007년 11월

각 ASP.NET 응용 프로그램은 루트 Web.config 파일에서 기본 구성 설정을 상속하기 때문에 기본 설정을 재정의하는 설정에 대해서만 Web.config 파일을 만들어야 합니다. 계층 구조에 다른 Web.config 파일이 있으면 응용 프로그램에서 상속하는 기본 설정을 모를 수도 있으므로 재정의해야 할 설정을 모를 수 있습니다.

이 예제에서는 비정적 메서드를 사용하여 구성 데이터를 가져오므로 모든 응용 프로그램에서 구성 정보를 가져올 수 있습니다. 사용 중인 코드가 있는 응용 프로그램에서 구성 정보를 가져오려면 처리 속도가 빠른 정적 메서드를 사용합니다. 자세한 내용은 ASP.NET 구성 API 개요에서 로컬 및 원격 구성 설정 사용 단원을 참조하십시오.

예제

다음 코드 예제에서는 기본 웹 사이트에서 MyApp라는 ASP.NET 응용 프로그램에 대한 모든 구성 설정을 가져온 다음 설정을 XML 파일에 씁니다.

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);
        }
    }
}

코드 컴파일

참고 항목

참조

OpenWebConfiguration

SaveAs

기타 리소스

방법 항목 - ASP.NET 응용 프로그램 구성

ASP.NET 웹 사이트 관리