WebConfigurationManager.OpenWebConfiguration 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
웹 애플리케이션 구성 파일을 개체로 Configuration 엽니다.
오버로드
| Name | Description |
|---|---|
| OpenWebConfiguration(String) |
지정된 가상 경로를 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다. |
| OpenWebConfiguration(String, String) |
지정된 가상 경로 및 사이트 이름을 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다. |
| OpenWebConfiguration(String, String, String) |
지정된 가상 경로, 사이트 이름 및 위치를 사용하여 읽기 또는 쓰기 작업을 허용하는 개체로 Configuration 웹 애플리케이션 구성 파일을 엽니다. |
| OpenWebConfiguration(String, String, String, String) |
지정된 가상 경로, 사이트 이름, 위치 및 서버를 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다. |
| OpenWebConfiguration(String, String, String, String, IntPtr) |
지정된 가상 경로, 사이트 이름, 위치, 서버 및 보안 컨텍스트를 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다. |
| OpenWebConfiguration(String, String, String, String, String, String) |
지정된 가상 경로, 사이트 이름, 위치, 서버 및 보안 컨텍스트를 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다. |
OpenWebConfiguration(String)
지정된 가상 경로를 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다.
public:
static System::Configuration::Configuration ^ OpenWebConfiguration(System::String ^ path);
public static System.Configuration.Configuration OpenWebConfiguration(string path);
static member OpenWebConfiguration : string -> System.Configuration.Configuration
Public Shared Function OpenWebConfiguration (path As String) As Configuration
매개 변수
- path
- String
구성 파일의 가상 경로입니다. 이 경우 null루트 Web.config 파일이 열립니다.
반품
Configuration 개체입니다.
예외
유효한 구성 파일을 로드할 수 없습니다.
예제
다음 예제에서는 메서드를 사용하여 구성 정보에 액세스하는 OpenWebConfiguration 방법을 보여줍니다.
// Show how to use OpenWebConfiguration(string).
// It gets he appSettings section of a Web application
// runnig on the local server.
static void OpenWebConfiguration1()
{
// Get the configuration object for a Web application
// running on the local server.
System.Configuration.Configuration config =
WebConfigurationManager.OpenWebConfiguration("/configTest")
as System.Configuration.Configuration;
// Get the appSettings.
KeyValueConfigurationCollection appSettings =
config.AppSettings.Settings;
// Loop through the collection and
// display the appSettings key, value pairs.
Console.WriteLine("[appSettings for app at: {0}]", "/configTest");
foreach (string key in appSettings.AllKeys)
{
Console.WriteLine("Name: {0} Value: {1}",
key, appSettings[key].Value);
}
Console.WriteLine();
}
' Show how to use OpenWebConfiguration(string).
' It gets he appSettings section of a Web application
' runnig on the local server.
Shared Sub OpenWebConfiguration1()
' Get the configuration object for a Web application
' running on the local server.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration("/configTest")
' Get the appSettings.
Dim appSettings As KeyValueConfigurationCollection = _
config.AppSettings.Settings
' Loop through the collection and
' display the appSettings key, value pairs.
Console.WriteLine("[appSettings for app at: {0}]", "/configTest")
Dim key As String
For Each key In appSettings.AllKeys
Console.WriteLine("Name: {0} Value: {1}", _
key, appSettings(key).Value)
Next key
Console.WriteLine()
End Sub
설명
리소스에 Configuration 대한 개체를 가져오려면 코드에 설정을 상속하는 모든 구성 파일에 대한 읽기 권한이 있어야 합니다. 구성 파일을 업데이트하려면 코드에 구성 파일과 해당 파일이 있는 디렉터리에 대한 쓰기 권한이 추가로 있어야 합니다.
추가 정보
적용 대상
OpenWebConfiguration(String, String)
지정된 가상 경로 및 사이트 이름을 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다.
public:
static System::Configuration::Configuration ^ OpenWebConfiguration(System::String ^ path, System::String ^ site);
public static System.Configuration.Configuration OpenWebConfiguration(string path, string site);
static member OpenWebConfiguration : string * string -> System.Configuration.Configuration
Public Shared Function OpenWebConfiguration (path As String, site As String) As Configuration
매개 변수
- path
- String
구성 파일의 가상 경로입니다.
- site
- String
IIS(인터넷 정보 서비스) 구성에 표시된 애플리케이션 웹 사이트의 이름입니다.
반품
Configuration 개체입니다.
예외
유효한 구성 파일을 로드할 수 없습니다.
예제
다음 예제에서는 메서드를 사용하여 구성 정보에 액세스하는 OpenWebConfiguration 방법을 보여줍니다.
// Show how to use OpenWebConfiguration(string, string).
// It gets he appSettings section of a Web application
// runnig on the local server.
static void OpenWebConfiguration2()
{
// Get the configuration object for a Web application
// running on the local server.
System.Configuration.Configuration config =
WebConfigurationManager.OpenWebConfiguration("/configTest",
"Default Web Site")
as System.Configuration.Configuration;
// Get the appSettings.
KeyValueConfigurationCollection appSettings =
config.AppSettings.Settings;
// Loop through the collection and
// display the appSettings key, value pairs.
Console.WriteLine(
"[appSettings for app at: /configTest");
Console.WriteLine(" and site: Default Web Site]");
foreach (string key in appSettings.AllKeys)
{
Console.WriteLine("Name: {0} Value: {1}",
key, appSettings[key].Value);
}
Console.WriteLine();
}
' Show how to use OpenWebConfiguration(string, string).
' It gets he appSettings section of a Web application
' runnig on the local server.
Shared Sub OpenWebConfiguration2()
' Get the configuration object for a Web application
' running on the local server.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration( _
"/configTest", "Default Web Site")
' Get the appSettings.
Dim appSettings As KeyValueConfigurationCollection = _
config.AppSettings.Settings
' Loop through the collection and
' display the appSettings key, value pairs.
Console.WriteLine("[appSettings for app at: /configTest")
Console.WriteLine(" and site: Default Web Site]")
Dim key As String
For Each key In appSettings.AllKeys
Console.WriteLine("Name: {0} Value: {1}", _
key, appSettings(key).Value)
Next key
Console.WriteLine()
End Sub
설명
리소스에 Configuration 대한 개체를 가져오려면 코드에 설정을 상속하는 모든 구성 파일에 대한 읽기 권한이 있어야 합니다. 구성 파일을 업데이트하려면 코드에 구성 파일과 해당 파일이 있는 디렉터리에 대한 쓰기 권한이 추가로 있어야 합니다.
추가 정보
적용 대상
OpenWebConfiguration(String, String, String)
지정된 가상 경로, 사이트 이름 및 위치를 사용하여 읽기 또는 쓰기 작업을 허용하는 개체로 Configuration 웹 애플리케이션 구성 파일을 엽니다.
public:
static System::Configuration::Configuration ^ OpenWebConfiguration(System::String ^ path, System::String ^ site, System::String ^ locationSubPath);
public static System.Configuration.Configuration OpenWebConfiguration(string path, string site, string locationSubPath);
static member OpenWebConfiguration : string * string * string -> System.Configuration.Configuration
Public Shared Function OpenWebConfiguration (path As String, site As String, locationSubPath As String) As Configuration
매개 변수
- path
- String
구성 파일의 가상 경로입니다.
- site
- String
IIS(인터넷 정보 서비스) 구성에 표시된 애플리케이션 웹 사이트의 이름입니다.
- locationSubPath
- String
구성이 적용되는 특정 리소스입니다.
반품
Configuration 개체입니다.
예외
유효한 구성 파일을 로드할 수 없습니다.
예제
다음 예제에서는 메서드를 사용하여 구성 정보에 액세스하는 OpenWebConfiguration 방법을 보여줍니다.
// Show how to use OpenWebConfiguration(string, string, string).
// It gets he appSettings section of a Web application
// runnig on the local server.
static void OpenWebConfiguration3()
{
// Get the configuration object for a Web application
// running on the local server.
System.Configuration.Configuration config =
WebConfigurationManager.OpenWebConfiguration(
"/configTest", "Default Web Site", null)
as System.Configuration.Configuration;
// Get the appSettings.
KeyValueConfigurationCollection appSettings =
config.AppSettings.Settings;
// Loop through the collection and
// display the appSettings key, value pairs.
Console.WriteLine(
"[appSettings for app at: /configTest");
Console.WriteLine(" site: Default Web Site");
Console.WriteLine(" and locationSubPath: null]");
foreach (string key in appSettings.AllKeys)
{
Console.WriteLine("Name: {0} Value: {1}",
key, appSettings[key].Value);
}
Console.WriteLine();
}
' Show how to use OpenWebConfiguration(string, string, string).
' It gets he appSettings section of a Web application
' runnig on the local server.
Shared Sub OpenWebConfiguration3()
' Get the configuration object for a Web application
' running on the local server.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration( _
"/configTest", "Default Web Site", Nothing)
' Get the appSettings.
Dim appSettings As KeyValueConfigurationCollection = _
config.AppSettings.Settings
' Loop through the collection and
' display the appSettings key, value pairs.
Console.WriteLine("[appSettings for app at: /configTest")
Console.WriteLine(" site: Default Web Site")
Console.WriteLine(" and locationSubPath: null]")
Dim key As String
For Each key In appSettings.AllKeys
Console.WriteLine("Name: {0} Value: {1}", _
key, appSettings(key).Value)
Next key
Console.WriteLine()
End Sub
설명
리소스에 Configuration 대한 개체를 가져오려면 코드에 설정을 상속하는 모든 구성 파일에 대한 읽기 권한이 있어야 합니다. 구성 파일을 업데이트하려면 코드에 구성 파일과 해당 파일이 있는 디렉터리에 대한 쓰기 권한이 추가로 있어야 합니다.
추가 정보
적용 대상
OpenWebConfiguration(String, String, String, String)
지정된 가상 경로, 사이트 이름, 위치 및 서버를 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다.
public:
static System::Configuration::Configuration ^ OpenWebConfiguration(System::String ^ path, System::String ^ site, System::String ^ locationSubPath, System::String ^ server);
public static System.Configuration.Configuration OpenWebConfiguration(string path, string site, string locationSubPath, string server);
static member OpenWebConfiguration : string * string * string * string -> System.Configuration.Configuration
Public Shared Function OpenWebConfiguration (path As String, site As String, locationSubPath As String, server As String) As Configuration
매개 변수
- path
- String
구성 파일의 가상 경로입니다.
- site
- String
IIS(인터넷 정보 서비스) 구성에 표시된 애플리케이션 웹 사이트의 이름입니다.
- locationSubPath
- String
구성이 적용되는 특정 리소스입니다.
- server
- String
웹 애플리케이션이 상주하는 서버의 네트워크 이름입니다.
반품
Configuration 개체입니다.
예외
서버 매개 변수가 잘못되었습니다.
유효한 구성 파일을 로드할 수 없습니다.
예제
다음 예제에서는 메서드를 사용하여 구성 정보에 액세스하는 OpenWebConfiguration 방법을 보여줍니다.
// Show how to use OpenWebConfiguration(string, string,
// string, string).
// It gets he appSettings section of a Web application
// running on the specified server.
// If the server is remote your application must have the
// required access rights to the configuration file.
static void OpenWebConfiguration4()
{
// Get the configuration object for a Web application
// running on the specified server.
// Null for the subPath signifies no subdir.
System.Configuration.Configuration config =
WebConfigurationManager.OpenWebConfiguration(
"/configTest", "Default Web Site", null, "myServer")
as System.Configuration.Configuration;
// Get the appSettings.
KeyValueConfigurationCollection appSettings =
config.AppSettings.Settings;
// Loop through the collection and
// display the appSettings key, value pairs.
Console.WriteLine("[appSettings for Web app on server: myServer]");
foreach (string key in appSettings.AllKeys)
{
Console.WriteLine("Name: {0} Value: {1}",
key, appSettings[key].Value);
}
Console.WriteLine();
}
' Show how to use OpenWebConfiguration(string, string,
' string, string).
' It gets he appSettings section of a Web application
' running on the specified server.
' If the server is remote your application must have the
' required access rights to the configuration file.
Shared Sub OpenWebConfiguration4()
' Get the configuration object for a Web application
' running on the specified server.
' Null for the subPath signifies no subdir.
Dim config As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration("/configTest", "Default Web Site", Nothing, "myServer")
' Get the appSettings.
Dim appSettings As KeyValueConfigurationCollection = config.AppSettings.Settings
' Loop through the collection and
' display the appSettings key, value pairs.
Console.WriteLine("[appSettings for Web app on server: myServer]")
Dim key As String
For Each key In appSettings.AllKeys
Console.WriteLine("Name: {0} Value: {1}", key, appSettings(key).Value)
Next key
Console.WriteLine()
End Sub
설명
원격 리소스에 Configuration 대한 개체를 가져오려면 코드에 원격 컴퓨터에 대한 관리 권한이 있어야 합니다.
추가 정보
적용 대상
OpenWebConfiguration(String, String, String, String, IntPtr)
지정된 가상 경로, 사이트 이름, 위치, 서버 및 보안 컨텍스트를 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다.
public:
static System::Configuration::Configuration ^ OpenWebConfiguration(System::String ^ path, System::String ^ site, System::String ^ locationSubPath, System::String ^ server, IntPtr userToken);
public static System.Configuration.Configuration OpenWebConfiguration(string path, string site, string locationSubPath, string server, IntPtr userToken);
static member OpenWebConfiguration : string * string * string * string * nativeint -> System.Configuration.Configuration
Public Shared Function OpenWebConfiguration (path As String, site As String, locationSubPath As String, server As String, userToken As IntPtr) As Configuration
매개 변수
- path
- String
구성 파일의 가상 경로입니다.
- site
- String
IIS(인터넷 정보 서비스) 구성에 표시된 애플리케이션 웹 사이트의 이름입니다.
- locationSubPath
- String
구성이 적용되는 특정 리소스입니다.
- server
- String
웹 애플리케이션이 상주하는 서버의 네트워크 이름입니다.
- userToken
-
IntPtr
nativeint
사용할 계정 토큰입니다.
반품
Configuration 개체입니다.
예외
server 또는 userToken 매개 변수가 잘못되었습니다.
유효한 구성 파일을 로드할 수 없습니다.
예제
다음 예제에서는 메서드를 사용하여 OpenWebConfiguration 구성 정보에 액세스하는 방법을 보여 있습니다.
// Show how to use OpenWebConfiguration(string, string,
// string, string, IntPtr).
// It gets he appSettings section of a Web application
// running on a remote server.
// If the serve is remote your application shall have the
// requires access rights to the configuration file.
static void OpenWebConfiguration6()
{
IntPtr userToken =
System.Security.Principal.WindowsIdentity.GetCurrent().Token;
string user =
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
// Get the configuration object for a Web application
// running on a remote server.
System.Configuration.Configuration config =
WebConfigurationManager.OpenWebConfiguration(
"/configTest", "Default Web Site", null,
"myServer", userToken) as System.Configuration.Configuration;
// Get the appSettings.
KeyValueConfigurationCollection appSettings =
config.AppSettings.Settings;
// Loop through the collection and
// display the appSettings key, value pairs.
Console.WriteLine(
"[appSettings for Web app on server: myServer user: {0}]", user);
foreach (string key in appSettings.AllKeys)
{
Console.WriteLine("Name: {0} Value: {1}",
key, appSettings[key].Value);
}
Console.WriteLine();
}
' Show how to use OpenWebConfiguration(string, string,
' string, string, IntPtr).
' It gets he appSettings section of a Web application
' running on a remote server.
' If the serve is remote your application shall have the
' requires access rights to the configuration file.
Shared Sub OpenWebConfiguration6()
Dim userToken As IntPtr = _
System.Security.Principal.WindowsIdentity.GetCurrent().Token
Dim user As String = _
System.Security.Principal.WindowsIdentity.GetCurrent().Name
' Get the configuration object for a Web application
' running on a remote server.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration( _
"/configTest", "Default Web Site", _
Nothing, "myServer", userToken)
' Get the appSettings.
Dim appSettings As KeyValueConfigurationCollection = _
config.AppSettings.Settings
' Loop through the collection and
' display the appSettings key, value pairs.
Console.WriteLine( _
"[appSettings for Web app on server: myServer user: {0}]", user)
Dim key As String
For Each key In appSettings.AllKeys
Console.WriteLine("Name: {0} Value: {1}", _
key, appSettings(key).Value)
Next key
Console.WriteLine()
End Sub
설명
이 메서드는 가장을 사용하여 구성 파일에 액세스하는 데 사용됩니다.
메모
계정 토큰은 일반적으로 WindowsIdentity 클래스의 인스턴스에서 또는 Windows API LogonUser 호출과 같은 관리되지 않는 코드에 대한 호출을 통해 검색됩니다. 관리되지 않는 코드 호출에 대한 자세한 내용은 관리되지 않는 DLL 함수를 사용하는 방법을 참조하세요.
원격 리소스에 Configuration 대한 개체를 가져오려면 코드에 원격 컴퓨터에 대한 관리 권한이 있어야 합니다.
추가 정보
적용 대상
OpenWebConfiguration(String, String, String, String, String, String)
지정된 가상 경로, 사이트 이름, 위치, 서버 및 보안 컨텍스트를 사용하여 웹 애플리케이션 구성 파일을 개체로 Configuration 열어 읽기 또는 쓰기 작업을 허용합니다.
public:
static System::Configuration::Configuration ^ OpenWebConfiguration(System::String ^ path, System::String ^ site, System::String ^ locationSubPath, System::String ^ server, System::String ^ userName, System::String ^ password);
public static System.Configuration.Configuration OpenWebConfiguration(string path, string site, string locationSubPath, string server, string userName, string password);
static member OpenWebConfiguration : string * string * string * string * string * string -> System.Configuration.Configuration
Public Shared Function OpenWebConfiguration (path As String, site As String, locationSubPath As String, server As String, userName As String, password As String) As Configuration
매개 변수
- path
- String
구성 파일의 가상 경로입니다.
- site
- String
IIS(인터넷 정보 서비스) 구성에 표시된 애플리케이션 웹 사이트의 이름입니다.
- locationSubPath
- String
구성이 적용되는 특정 리소스입니다.
- server
- String
웹 애플리케이션이 상주하는 서버의 네트워크 이름입니다.
- userName
- String
파일을 열 때 사용할 전체 사용자 이름(Domain\User)입니다.
- password
- String
사용자 이름의 암호입니다.
반품
Configuration 개체입니다.
예외
server 또는 userNamepassword 매개 변수가 잘못되었습니다.
유효한 구성 파일을 로드할 수 없습니다.
예제
다음 예제에서는 메서드를 사용하여 구성 정보에 액세스하는 OpenWebConfiguration 방법을 보여줍니다.
// Show how to use OpenWebConfiguration(string, string,
// string, string, string, string).
// It gets he appSettings section of a Web application
// running on a remote server.
// If the server is remote your application must have the
// required access rights to the configuration file.
static void OpenWebConfiguration5()
{
// Get the current user.
string user =
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
// Assign the actual password.
string password = "userPassword";
// Get the configuration object for a Web application
// running on a remote server.
System.Configuration.Configuration config =
WebConfigurationManager.OpenWebConfiguration(
"/configTest", "Default Web Site", null, "myServer",
user, password) as System.Configuration.Configuration;
// Get the appSettings.
KeyValueConfigurationCollection appSettings =
config.AppSettings.Settings;
// Loop through the collection and
// display the appSettings key, value pairs.
Console.WriteLine(
"[appSettings for Web app on server: myServer user: {0}]", user);
foreach (string key in appSettings.AllKeys)
{
Console.WriteLine("Name: {0} Value: {1}",
key, appSettings[key].Value);
}
Console.WriteLine();
}
' Show how to use OpenWebConfiguration(string, string,
' string, string, string, string).
' It gets he appSettings section of a Web application
' running on a remote server.
' If the server is remote your application must have the
' required access rights to the configuration file.
Shared Sub OpenWebConfiguration5()
' Get the current user.
Dim user As String = _
System.Security.Principal.WindowsIdentity.GetCurrent().Name
' Assign the actual password.
Dim password As String = "userPassword"
' Get the configuration object for a Web application
' running on a remote server.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration( _
"/configTest", "Default Web Site", _
Nothing, "myServer", user, password)
' Get the appSettings.
Dim appSettings As KeyValueConfigurationCollection = _
config.AppSettings.Settings
' Loop through the collection and
' display the appSettings key, value pairs.
Console.WriteLine( _
"[appSettings for Web app on server: myServer user: {0}]", user)
Dim key As String
For Each key In appSettings.AllKeys
Console.WriteLine("Name: {0} Value: {1}", _
key, appSettings(key).Value)
Next key
Console.WriteLine()
End Sub
설명
이 메서드는 가장을 사용하여 구성 파일에 액세스하는 데 사용됩니다.
원격 리소스에 Configuration 대한 개체를 가져오려면 코드에 원격 컴퓨터에 대한 관리 권한이 있어야 합니다.
원격 컴퓨터의 구성 파일에 액세스할 수 있도록 ASP.NET IIS 등록 도구(Aspnet_regiis.exe)를 -config+ 옵션으로 실행해야 할 수 있습니다.