Aracılığıyla paylaş


WebConfigurationManager.OpenWebConfiguration Yöntem

Tanım

Web uygulaması yapılandırma dosyasını nesne Configuration olarak açar.

Aşırı Yüklemeler

OpenWebConfiguration(String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu kullanarak bir Configuration nesne olarak açar.

OpenWebConfiguration(String, String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu ve site adını kullanarak bir Configuration nesne olarak açar.

OpenWebConfiguration(String, String, String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu, site adını ve konumu kullanarak bir Configuration nesne olarak açar.

OpenWebConfiguration(String, String, String, String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu, site adını, konumu ve sunucuyu kullanarak bir Configuration nesne olarak açar.

OpenWebConfiguration(String, String, String, String, IntPtr)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu, site adını, konumu, sunucuyu ve güvenlik bağlamını kullanarak bir Configuration nesne olarak açar.

OpenWebConfiguration(String, String, String, String, String, String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu, site adını, konumu, sunucuyu ve güvenlik bağlamını kullanarak bir Configuration nesne olarak açar.

OpenWebConfiguration(String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu kullanarak bir Configuration nesne olarak açar.

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

Parametreler

path
String

Yapılandırma dosyasının sanal yolu. ise null, kök Web.config dosyası açılır.

Döndürülenler

Bir Configuration nesnesi.

Özel durumlar

Geçerli bir yapılandırma dosyası yüklenemedi.

Örnekler

Aşağıdaki örnek, yöntemiyle yapılandırma bilgilerine nasıl erişeceklerini OpenWebConfiguration gösterir.


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

Açıklamalar

Bir kaynağın Configuration nesnesini almak için kodunuzun ayarları devraldığı tüm yapılandırma dosyalarında okuma ayrıcalıklarına sahip olması gerekir. Bir yapılandırma dosyasını güncelleştirmek için kodunuzun hem yapılandırma dosyası hem de bulunduğu dizin için yazma ayrıcalıklarına sahip olması gerekir.

Ayrıca bkz.

Şunlara uygulanır

OpenWebConfiguration(String, String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu ve site adını kullanarak bir Configuration nesne olarak açar.

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

Parametreler

path
String

Yapılandırma dosyasının sanal yolu.

site
String

Internet Information Services (IIS) yapılandırmasında gösterildiği gibi uygulama Web sitesinin adı.

Döndürülenler

Bir Configuration nesnesi.

Özel durumlar

Geçerli bir yapılandırma dosyası yüklenemedi.

Örnekler

Aşağıdaki örnek, yöntemiyle yapılandırma bilgilerine nasıl erişeceklerini OpenWebConfiguration gösterir.


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

Açıklamalar

Bir kaynağın Configuration nesnesini almak için kodunuzun ayarları devraldığı tüm yapılandırma dosyalarında okuma ayrıcalıklarına sahip olması gerekir. Bir yapılandırma dosyasını güncelleştirmek için kodunuzun hem yapılandırma dosyası hem de bulunduğu dizin için yazma ayrıcalıklarına sahip olması gerekir.

Ayrıca bkz.

Şunlara uygulanır

OpenWebConfiguration(String, String, String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu, site adını ve konumu kullanarak bir Configuration nesne olarak açar.

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

Parametreler

path
String

Yapılandırma dosyasının sanal yolu.

site
String

Internet Information Services (IIS) yapılandırmasında gösterildiği gibi uygulama Web sitesinin adı.

locationSubPath
String

Yapılandırmanın geçerli olduğu kaynak.

Döndürülenler

Bir Configuration nesnesi.

Özel durumlar

Geçerli bir yapılandırma dosyası yüklenemedi.

Örnekler

Aşağıdaki örnek, yöntemiyle yapılandırma bilgilerine nasıl erişeceklerini OpenWebConfiguration gösterir.


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

Açıklamalar

Bir kaynağın Configuration nesnesini almak için kodunuzun ayarları devraldığı tüm yapılandırma dosyalarında okuma ayrıcalıklarına sahip olması gerekir. Bir yapılandırma dosyasını güncelleştirmek için kodunuzun hem yapılandırma dosyası hem de bulunduğu dizin için yazma ayrıcalıklarına sahip olması gerekir.

Ayrıca bkz.

Şunlara uygulanır

OpenWebConfiguration(String, String, String, String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu, site adını, konumu ve sunucuyu kullanarak bir Configuration nesne olarak açar.

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

Parametreler

path
String

Yapılandırma dosyasının sanal yolu.

site
String

Internet Information Services (IIS) yapılandırmasında gösterildiği gibi uygulama Web sitesinin adı.

locationSubPath
String

Yapılandırmanın geçerli olduğu kaynak.

server
String

Web uygulamasının bulunduğu sunucunun ağ adı.

Döndürülenler

Bir Configuration nesnesi.

Özel durumlar

Sunucu parametresi geçersizdi.

Geçerli bir yapılandırma dosyası yüklenemedi.

Örnekler

Aşağıdaki örnek, yöntemiyle yapılandırma bilgilerine nasıl erişeceklerini OpenWebConfiguration gösterir.


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

Açıklamalar

Uzak bir kaynağın Configuration nesnesini almak için kodunuzun uzak bilgisayarda yönetici ayrıcalıklarına sahip olması gerekir.

Ayrıca bkz.

Şunlara uygulanır

OpenWebConfiguration(String, String, String, String, IntPtr)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu, site adını, konumu, sunucuyu ve güvenlik bağlamını kullanarak bir Configuration nesne olarak açar.

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

Parametreler

path
String

Yapılandırma dosyasının sanal yolu.

site
String

Internet Information Services (IIS) yapılandırmasında gösterildiği gibi uygulama Web sitesinin adı.

locationSubPath
String

Yapılandırmanın geçerli olduğu kaynak.

server
String

Web uygulamasının bulunduğu sunucunun ağ adı.

userToken
IntPtr

nativeint

Kullanılacak hesap belirteci.

Döndürülenler

Bir Configuration nesnesi.

Özel durumlar

server veya userToken parametreleri geçersizdi.

Geçerli bir yapılandırma dosyası yüklenemedi.

Örnekler

Aşağıdaki örnekte, yapılandırma bilgilerine erişmek için yönteminin OpenWebConfiguration nasıl kullanılacağı gösterilmektedir.


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

Açıklamalar

Bu yöntem, kimliğe bürünme kullanılarak bir yapılandırma dosyasına erişmek için kullanılır.

Not

Hesap belirteci genellikle sınıfının bir örneğinden WindowsIdentity veya Windows API LogonUserçağrısı gibi yönetilmeyen kod çağrısı aracılığıyla alınır. Yönetilmeyen koda yapılan çağrılar hakkında daha fazla bilgi için bkz . Yönetilmeyen DLL İşlevlerini Kullanma.

Uzak bir kaynağın Configuration nesnesini almak için kodunuzun uzak bilgisayarda yönetici ayrıcalıklarına sahip olması gerekir.

Ayrıca bkz.

Şunlara uygulanır

OpenWebConfiguration(String, String, String, String, String, String)

Web uygulaması yapılandırma dosyasını, okuma veya yazma işlemlerine izin vermek için belirtilen sanal yolu, site adını, konumu, sunucuyu ve güvenlik bağlamını kullanarak bir Configuration nesne olarak açar.

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

Parametreler

path
String

Yapılandırma dosyasının sanal yolu.

site
String

Internet Information Services (IIS) yapılandırmasında gösterildiği gibi uygulama Web sitesinin adı.

locationSubPath
String

Yapılandırmanın geçerli olduğu kaynak.

server
String

Web uygulamasının bulunduğu sunucunun ağ adı.

userName
String

Dosyayı açarken kullanılacak tam kullanıcı adı (Domain\User).

password
String

Kullanıcı adının parolası.

Döndürülenler

Bir Configuration nesnesi.

Özel durumlar

server veya userName ve password parametreleri geçersizdi.

Geçerli bir yapılandırma dosyası yüklenemedi.

Örnekler

Aşağıdaki örnek, yöntemiyle yapılandırma bilgilerine nasıl erişeceklerini OpenWebConfiguration gösterir.


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

Açıklamalar

Bu yöntem, kimliğe bürünme kullanılarak bir yapılandırma dosyasına erişmek için kullanılır.

Uzak bir kaynağın Configuration nesnesini almak için kodunuzun uzak bilgisayarda yönetici ayrıcalıklarına sahip olması gerekir.

uzak bilgisayardaki yapılandırma dosyalarına erişimi etkinleştirme seçeneğiyle ASP.NET IIS Kayıt Aracı'nı-config+ (Aspnet_regiis.exe) çalıştırmanız gerekebilir.

Ayrıca bkz.

Şunlara uygulanır