WebConfigurationManager.GetWebApplicationSection(String) 메서드

정의

현재 웹 애플리케이션의 구성 파일에서 지정된 구성 섹션을 검색합니다.

public:
 static System::Object ^ GetWebApplicationSection(System::String ^ sectionName);
public static object GetWebApplicationSection(string sectionName);
static member GetWebApplicationSection : string -> obj
Public Shared Function GetWebApplicationSection (sectionName As String) As Object

매개 변수

sectionName
String

구성 섹션 이름입니다.

반품

지정된 구성 섹션 개체 또는 null 섹션이 없는 경우 또는 런타임에 섹션에 액세스할 수 없는 경우 내부 개체입니다.

예외

유효한 구성 파일을 로드할 수 없습니다.

예제

다음 예제에서는 메서드를 사용하여 구성 정보에 액세스하는 GetWebApplicationSection 방법을 보여줍니다.

메모

이 예제에서는 메서드를 사용하여 GetWebApplicationSection 기본 구성 파일에서 개체를 ConfigurationSection 가져오는 방법을 보여 줍니다.


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

     // Get the default connectionStrings section,
     ConnectionStringsSection connectionStringsSection =
         WebConfigurationManager.GetWebApplicationSection(
         "connectionStrings") as ConnectionStringsSection;

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

     // Get the collection enumerator.
     IEnumerator connectionStringsEnum =
         connectionStrings.GetEnumerator();

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

     Console.WriteLine();
 }
' Show the use of GetWebApplicationSection(string). 
' to access the connectionStrings section.
Shared Sub GetWebApplicationSection()
   
   ' Get the default connectionStrings section,
     Dim connectionStringsSection As ConnectionStringsSection = _
     WebConfigurationManager.GetWebApplicationSection( _
     "connectionStrings")
   
   ' Get the connectionStrings key,value pairs collection.
     Dim connectionStrings As ConnectionStringSettingsCollection = _
     connectionStringsSection.ConnectionStrings
   
   ' Get the collection enumerator.
     Dim connectionStringsEnum As IEnumerator = _
     connectionStrings.GetEnumerator()
   
   ' Loop through the collection and 
   ' display the connectionStrings key, value pairs.
   Dim i As Integer = 0
   Console.WriteLine("[Display connectionStrings]")
   While connectionStringsEnum.MoveNext()
      Dim name As String = connectionStrings(i).Name
         Console.WriteLine("Name: {0} Value: {1}", _
         name, connectionStrings(name))
      i += 1
   End While
   
   Console.WriteLine()
End Sub

설명

웹 애플리케이션 내에서 호출되는 경우 GetWebApplicationSection 웹 애플리케이션 구성 계층 구조에 따라 시스템에서 선택한 구성 파일에서 섹션을 가져옵니다.

클라이언트 애플리케이션 내에서 호출 GetWebApplicationSection 할 수 있습니다. 이 경우 클라이언트 구성 계층 구조에 따라 시스템에서 선택한 구성 파일에서 기본 섹션을 가져옵니다. 일반적으로 매핑된 구성이 없으면 이 파일은 Machine.config 파일입니다. 매핑 구성 파일의 경우 다음에 설명된 매핑 방법을 참조하세요.

메모

GetWebApplicationSection 메서드는 현재 수준에 있는 애플리케이션 구성 파일의 섹션에서 작동하는 런타임 작업입니다. 그러나 이 메서드는 GetSection 런타임 작업이 아니지만 구성 파일을 여는 방법 중 하나를 통해 가져온 지정된 섹션에서 작동합니다.

상속자 참고

반환 값은 사용하기 전에 예상된 구성 형식으로 캐스팅해야 합니다. 가능한 캐스팅 예외를 방지하려면 C#의 연산자처럼 as 조건부 캐스팅 작업을 사용해야 합니다.

적용 대상

추가 정보