WebConfigurationManager.OpenWebConfiguration Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object.
Overloads
| Name | Description |
|---|---|
| OpenWebConfiguration(String) |
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad om lees- of schrijfbewerkingen toe te staan. |
| OpenWebConfiguration(String, String) |
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad en de sitenaam om lees- of schrijfbewerkingen toe te staan. |
| OpenWebConfiguration(String, String, String) |
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad, de sitenaam en de locatie om lees- of schrijfbewerkingen toe te staan. |
| OpenWebConfiguration(String, String, String, String) |
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad, de sitenaam, de locatie en de server om lees- of schrijfbewerkingen toe te staan. |
| OpenWebConfiguration(String, String, String, String, IntPtr) |
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad, de sitenaam, de locatie, de server en de beveiligingscontext om lees- of schrijfbewerkingen toe te staan. |
| OpenWebConfiguration(String, String, String, String, String, String) |
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad, de sitenaam, de locatie, de server en de beveiligingscontext om lees- of schrijfbewerkingen toe te staan. |
OpenWebConfiguration(String)
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad om lees- of schrijfbewerkingen toe te staan.
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
Parameters
- path
- String
Het virtuele pad naar het configuratiebestand. Als null, wordt het hoofdbestand Web.config geopend.
Retouren
Een Configuration-object.
Uitzonderingen
Er kan geen geldig configuratiebestand worden geladen.
Voorbeelden
In het volgende voorbeeld ziet u hoe u met de OpenWebConfiguration methode toegang hebt tot configuratiegegevens.
// 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
Opmerkingen
Als u het Configuration object voor een resource wilt ophalen, moet uw code leesmachtigingen hebben voor alle configuratiebestanden waaruit de instellingen worden overgenomen. Als u een configuratiebestand wilt bijwerken, moet uw code bovendien schrijfbevoegdheden hebben voor zowel het configuratiebestand als de map waarin het bestand bestaat.
Zie ook
Van toepassing op
OpenWebConfiguration(String, String)
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad en de sitenaam om lees- of schrijfbewerkingen toe te staan.
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
Parameters
- path
- String
Het virtuele pad naar het configuratiebestand.
- site
- String
De naam van de toepassingswebsite, zoals weergegeven in de configuratie van Internet Information Services (IIS).
Retouren
Een Configuration-object.
Uitzonderingen
Er kan geen geldig configuratiebestand worden geladen.
Voorbeelden
In het volgende voorbeeld ziet u hoe u met de OpenWebConfiguration methode toegang hebt tot configuratiegegevens.
// 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
Opmerkingen
Als u het Configuration object voor een resource wilt ophalen, moet uw code leesmachtigingen hebben voor alle configuratiebestanden waaruit de instellingen worden overgenomen. Als u een configuratiebestand wilt bijwerken, moet uw code bovendien schrijfbevoegdheden hebben voor zowel het configuratiebestand als de map waarin het bestand bestaat.
Zie ook
Van toepassing op
OpenWebConfiguration(String, String, String)
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad, de sitenaam en de locatie om lees- of schrijfbewerkingen toe te staan.
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
Parameters
- path
- String
Het virtuele pad naar het configuratiebestand.
- site
- String
De naam van de toepassingswebsite, zoals weergegeven in de configuratie van Internet Information Services (IIS).
- locationSubPath
- String
De specifieke resource waarop de configuratie van toepassing is.
Retouren
Een Configuration-object.
Uitzonderingen
Er kan geen geldig configuratiebestand worden geladen.
Voorbeelden
In het volgende voorbeeld ziet u hoe u met de OpenWebConfiguration methode toegang hebt tot configuratiegegevens.
// 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
Opmerkingen
Als u het Configuration object voor een resource wilt ophalen, moet uw code leesmachtigingen hebben voor alle configuratiebestanden waaruit de instellingen worden overgenomen. Als u een configuratiebestand wilt bijwerken, moet uw code bovendien schrijfbevoegdheden hebben voor zowel het configuratiebestand als de map waarin het bestand bestaat.
Zie ook
Van toepassing op
OpenWebConfiguration(String, String, String, String)
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad, de sitenaam, de locatie en de server om lees- of schrijfbewerkingen toe te staan.
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
Parameters
- path
- String
Het virtuele pad naar het configuratiebestand.
- site
- String
De naam van de toepassingswebsite, zoals weergegeven in de configuratie van Internet Information Services (IIS).
- locationSubPath
- String
De specifieke resource waarop de configuratie van toepassing is.
- server
- String
De netwerknaam van de server waarop de webtoepassing zich bevindt.
Retouren
Een Configuration-object.
Uitzonderingen
De serverparameter is ongeldig.
Er kan geen geldig configuratiebestand worden geladen.
Voorbeelden
In het volgende voorbeeld ziet u hoe u met de OpenWebConfiguration methode toegang hebt tot configuratiegegevens.
// 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
Opmerkingen
Als u het Configuration object voor een externe resource wilt verkrijgen, moet uw code beheerdersbevoegdheden hebben op de externe computer.
Zie ook
Van toepassing op
OpenWebConfiguration(String, String, String, String, IntPtr)
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad, de sitenaam, de locatie, de server en de beveiligingscontext om lees- of schrijfbewerkingen toe te staan.
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
Parameters
- path
- String
Het virtuele pad naar het configuratiebestand.
- site
- String
De naam van de toepassingswebsite, zoals weergegeven in de configuratie van Internet Information Services (IIS).
- locationSubPath
- String
De specifieke resource waarop de configuratie van toepassing is.
- server
- String
De netwerknaam van de server waarop de webtoepassing zich bevindt.
- userToken
-
IntPtr
nativeint
Een accounttoken dat moet worden gebruikt.
Retouren
Een Configuration-object.
Uitzonderingen
De server of userToken parameters zijn ongeldig.
Er kan geen geldig configuratiebestand worden geladen.
Voorbeelden
In het volgende voorbeeld ziet u hoe u de OpenWebConfiguration methode gebruikt voor toegang tot configuratiegegevens.
// 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
Opmerkingen
Deze methode wordt gebruikt voor toegang tot een configuratiebestand met behulp van imitatie.
Note
Het accounttoken wordt meestal opgehaald uit een exemplaar van de klasse WindowsIdentity of via een aanroep naar onbeheerde code, zoals een aanroep naar de Windows-API LogonUser. Zie Onbeheerde DLL-functies gebruiken voor meer informatie over aanroepen naar niet-beheerde code.
Als u het Configuration object voor een externe resource wilt verkrijgen, moet uw code beheerdersbevoegdheden hebben op de externe computer.
Zie ook
Van toepassing op
OpenWebConfiguration(String, String, String, String, String, String)
Hiermee opent u het configuratiebestand van de webtoepassing als een Configuration object met behulp van het opgegeven virtuele pad, de sitenaam, de locatie, de server en de beveiligingscontext om lees- of schrijfbewerkingen toe te staan.
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
Parameters
- path
- String
Het virtuele pad naar het configuratiebestand.
- site
- String
De naam van de toepassingswebsite, zoals weergegeven in de configuratie van Internet Information Services (IIS).
- locationSubPath
- String
De specifieke resource waarop de configuratie van toepassing is.
- server
- String
De netwerknaam van de server waarop de webtoepassing zich bevindt.
- userName
- String
De volledige gebruikersnaam (Domein\Gebruiker) die moet worden gebruikt bij het openen van het bestand.
- password
- String
Het wachtwoord voor de gebruikersnaam.
Retouren
Een Configuration-object.
Uitzonderingen
De server of-parameters userNamepassword zijn ongeldig.
Kan een geldig configuratiebestand niet laden.
Voorbeelden
In het volgende voorbeeld ziet u hoe u met de OpenWebConfiguration methode toegang hebt tot configuratiegegevens.
// 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
Opmerkingen
Deze methode wordt gebruikt voor toegang tot een configuratiebestand met behulp van imitatie.
Als u het Configuration object voor een externe resource wilt verkrijgen, moet uw code beheerdersbevoegdheden hebben op de externe computer.
Mogelijk moet u het ASP.NET IIS-registratieprogramma (Aspnet_regiis.exe) uitvoeren met de optie -config+ om toegang tot de configuratiebestanden op de externe computer in te schakelen.