WebConfigurationManager.OpenMachineConfiguration Methode

Definition

Öffnet die Computerkonfigurationsdatei als Configuration-Objekt, um Lese- oder Schreibvorgänge zu ermöglichen.

Überlädt

OpenMachineConfiguration()

Öffnet die Computerkonfigurationsdatei auf dem aktuell verwendeten Computer als Configuration-Objekt, um Lese- oder Schreibvorgänge zu ermöglichen.

OpenMachineConfiguration(String)

Öffnet die Computerkonfigurationsdatei auf dem aktuell verwendeten Computer als Configuration-Objekt, um Lese- oder Schreibvorgänge zu ermöglichen.

OpenMachineConfiguration(String, String)

Öffnet die angegebene Computerkonfigurationsdatei auf dem angegebenen Server als Configuration-Objekt, um Lese- oder Schreibvorgänge zu ermöglichen.

OpenMachineConfiguration(String, String, IntPtr)

Öffnet die angegebene Computerkonfigurationsdatei auf dem angegebenen Server als Configuration-Objekt, um mithilfe des angegebenen Sicherheitskontexts Lese- oder Schreibvorgänge zu ermöglichen.

OpenMachineConfiguration(String, String, String, String)

Öffnet die angegebene Computerkonfigurationsdatei auf dem angegebenen Server als Configuration-Objekt, um mithilfe des angegebenen Sicherheitskontexts Lese- oder Schreibvorgänge zu ermöglichen.

OpenMachineConfiguration()

Öffnet die Computerkonfigurationsdatei auf dem aktuell verwendeten Computer als Configuration-Objekt, um Lese- oder Schreibvorgänge zu ermöglichen.

public:
 static System::Configuration::Configuration ^ OpenMachineConfiguration();
public static System.Configuration.Configuration OpenMachineConfiguration ();
static member OpenMachineConfiguration : unit -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration () As Configuration

Gibt zurück

Configuration

Ein Configuration-Objekt.

Ausnahmen

Es konnte keine gültige Konfigurationsdatei geladen werden.

Beispiele

Im folgenden Beispiel wird gezeigt, wie Sie auf Konfigurationsinformationen mit der OpenMachineConfiguration Methode zugreifen.


// Show how to use OpenMachineConfiguration().
// It gets the machine.config file on the current 
// machine and displays section information. 
static void OpenMachineConfiguration1()
{
    // Get the machine.config file on the current machine.
    System.Configuration.Configuration config =
            WebConfigurationManager.OpenMachineConfiguration();

    // Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition");
    int i = 0;
    foreach (ConfigurationSection section in config.Sections)
    {
        Console.WriteLine(
            section.SectionInformation.Name + "\t" +
        section.SectionInformation.AllowExeDefinition);
        i += 1;
    }
    Console.WriteLine("[Total number of sections: {0}]", i);

    // Display machine.config path.
    Console.WriteLine("[File path: {0}]", config.FilePath); 
}
' Show how to use OpenMachineConfiguration().
' It gets the machine.config file on the current 
' machine and displays section information. 
Shared Sub OpenMachineConfiguration1()
   ' Get the machine.config file on the current machine.
     Dim config As System.Configuration.Configuration = _
     WebConfigurationManager.OpenMachineConfiguration()
   
   ' Loop to get the sections. Display basic information.
   Console.WriteLine("Name, Allow Definition")
   Dim i As Integer = 0
   Dim section As ConfigurationSection
   For Each section In  config.Sections
         Console.WriteLine((section.SectionInformation.Name + _
         ControlChars.Tab + _
         section.SectionInformation.AllowExeDefinition.ToString()))
         i += 1
     Next section
     Console.WriteLine("[Total number of sections: {0}]", i)

     ' Display machine.config path.
     Console.WriteLine("[File path: {0}]", config.FilePath)
 End Sub

Hinweise

Die OpenMachineConfiguration Methode öffnet die Computerkonfigurationsdatei auf dem Computer, auf dem die Anwendung ausgeführt wird. Diese Datei befindet sich im Standard-Buildverzeichnis %windir%\Microsoft.NET\Framework\version\config.

Siehe auch

Gilt für

OpenMachineConfiguration(String)

Öffnet die Computerkonfigurationsdatei auf dem aktuell verwendeten Computer als Configuration-Objekt, um Lese- oder Schreibvorgänge zu ermöglichen.

public:
 static System::Configuration::Configuration ^ OpenMachineConfiguration(System::String ^ locationSubPath);
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath);
static member OpenMachineConfiguration : string -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration (locationSubPath As String) As Configuration

Parameter

locationSubPath
String

Der Anwendungspfad, für den die Computerkonfiguration gilt.

Gibt zurück

Configuration

Ein Configuration-Objekt.

Ausnahmen

Es konnte keine gültige Konfigurationsdatei geladen werden.

Beispiele

Im folgenden Beispiel wird gezeigt, wie Sie auf Konfigurationsinformationen mit der OpenMachineConfiguration Methode zugreifen.


// Show how to use OpenMachineConfiguration(string).
// It gets the machine.config file applicabe to the
// specified resource and displays section 
// basic information. 
static void OpenMachineConfiguration2()
{
    // Get the machine.config file applicabe to the
    // specified reosurce.
    System.Configuration.Configuration config =
        WebConfigurationManager.OpenMachineConfiguration("configTest");

    // Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition");
    int i = 0;
    foreach (ConfigurationSection section in config.Sections)
    {
        Console.WriteLine(
            section.SectionInformation.Name + "\t" +
        section.SectionInformation.AllowExeDefinition);
        i += 1;
    }
    Console.WriteLine("[Total number of sections: {0}]", i);

    // Display machine.config path.
    Console.WriteLine("[File path: {0}]", config.FilePath);
}
' Show how to use OpenMachineConfiguration(string).
' It gets the machine.config file applicabe to the
' specified resource and displays section 
' basic information. 
Shared Sub OpenMachineConfiguration2()
    ' Get the machine.config file applicabe to the
    ' specified reosurce.
    Dim config As System.Configuration.Configuration = _
    WebConfigurationManager.OpenMachineConfiguration( _
    "configTest")

    ' Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition")
    Dim i As Integer = 0
    Dim section As ConfigurationSection
    For Each section In config.Sections
        Console.WriteLine((section.SectionInformation.Name + _
        ControlChars.Tab + _
        section.SectionInformation.AllowExeDefinition.ToString()))
        i += 1
    Next section
    Console.WriteLine("[Total number of sections: {0}]", i)

    ' Display machine.config path.
    Console.WriteLine("[File path: {0}]", config.FilePath)
End Sub

Hinweise

Diese Methode öffnet die Computerkonfigurationsdatei, die auf das locationSubPath vom Parameter angegebene Verzeichnis anwendbar ist.

Siehe auch

Gilt für

OpenMachineConfiguration(String, String)

Öffnet die angegebene Computerkonfigurationsdatei auf dem angegebenen Server als Configuration-Objekt, um Lese- oder Schreibvorgänge zu ermöglichen.

public:
 static System::Configuration::Configuration ^ OpenMachineConfiguration(System::String ^ locationSubPath, System::String ^ server);
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath, string server);
static member OpenMachineConfiguration : string * string -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration (locationSubPath As String, server As String) As Configuration

Parameter

locationSubPath
String

Der Anwendungspfad, für den die Konfiguration gilt.

server
String

Der vollqualifizierte Name des Servers, dessen Konfiguration zurückgegeben werden soll.

Gibt zurück

Configuration

Ein Configuration-Objekt.

Ausnahmen

Es konnte keine gültige Konfigurationsdatei geladen werden.

Beispiele

Im folgenden Beispiel wird gezeigt, wie Sie auf Konfigurationsinformationen mit der OpenMachineConfiguration Methode zugreifen.


// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server and
// applicabe to the specified reosurce and displays section 
// basic information. 
static void OpenMachineConfiguration3()
{
    // Get the machine.config file applicabe to the
    // specified reosurce and on the specified server.
    System.Configuration.Configuration config =
        WebConfigurationManager.OpenMachineConfiguration("configTest", 
        "myServer");

    // Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition");
    int i = 0;
    foreach (ConfigurationSection section in config.Sections)
    {
        Console.WriteLine(
            section.SectionInformation.Name + "\t" +
        section.SectionInformation.AllowExeDefinition);
        i += 1;
    }
    Console.WriteLine("[Total number of sections: {0}]", i);

    // Display machine.config path.
    Console.WriteLine("[File path: {0}]", config.FilePath);
}
' Show how to use OpenMachineConfiguration(string, string).
' It gets the machine.config file on the specified server and
' applicabe to the specified reosurce and displays section 
' basic information. 
Shared Sub OpenMachineConfiguration3()
    ' Get the machine.config file applicabe to the
    ' specified reosurce and on the specified server.
    Dim config As System.Configuration.Configuration = _
    WebConfigurationManager.OpenMachineConfiguration( _
    "configTest", "myServer")

    ' Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition")
    Dim i As Integer = 0
    Dim section As ConfigurationSection
    For Each section In config.Sections
        Console.WriteLine((section.SectionInformation.Name + _
        ControlChars.Tab + _
        section.SectionInformation.AllowExeDefinition.ToString()))
        i += 1
    Next section
    Console.WriteLine("[Total number of sections: {0}]", i)

    ' Display machine.config path.
    Console.WriteLine("[File path: {0}]", config.FilePath)
End Sub

Hinweise

Diese Methode öffnet die Computerkonfigurationsdatei, die sich im vom Parameter angegebenen Verzeichnis befindet und auf dem computer, der vom locationSubPath server Parameter angegeben ist.

Siehe auch

Gilt für

OpenMachineConfiguration(String, String, IntPtr)

Öffnet die angegebene Computerkonfigurationsdatei auf dem angegebenen Server als Configuration-Objekt, um mithilfe des angegebenen Sicherheitskontexts Lese- oder Schreibvorgänge zu ermöglichen.

public:
 static System::Configuration::Configuration ^ OpenMachineConfiguration(System::String ^ locationSubPath, System::String ^ server, IntPtr userToken);
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath, string server, IntPtr userToken);
static member OpenMachineConfiguration : string * string * nativeint -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration (locationSubPath As String, server As String, userToken As IntPtr) As Configuration

Parameter

locationSubPath
String

Der Anwendungspfad, für den die Konfiguration gilt.

server
String

Der vollqualifizierte Name des Servers, dessen Konfiguration zurückgegeben werden soll.

userToken
IntPtr

nativeint

Ein zu verwendendes Kontotoken.

Gibt zurück

Configuration

Ein Configuration-Objekt.

Ausnahmen

Für den server-Parameter oder den userToken-Parameter wurden keine gültigen Werte angegeben.

Es konnte keine gültige Konfigurationsdatei geladen werden.

Beispiele

Im folgenden Beispiel wird gezeigt, wie Sie auf Konfigurationsinformationen mit der OpenMachineConfiguration Methode zugreifen.


// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server,
// applicabe to the specified reosurce, for the specified user
// and displays section basic information. 
static void OpenMachineConfiguration4()
{
    // Get the current user token.
    IntPtr userToken =
          System.Security.Principal.WindowsIdentity.GetCurrent().Token;

    // Get the machine.config file applicabe to the
    // specified reosurce, on the specified server for the
    // specified user.
    System.Configuration.Configuration config =
        WebConfigurationManager.OpenMachineConfiguration("configTest",
        "myServer", userToken);

    // Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition");
    int i = 0;
    foreach (ConfigurationSection section in config.Sections)
    {
        Console.WriteLine(
            section.SectionInformation.Name + "\t" +
        section.SectionInformation.AllowExeDefinition);
        i += 1;
    }
    Console.WriteLine("[Total number of sections: {0}]", i);

    // Display machine.config path.
    Console.WriteLine("[File path: {0}]", config.FilePath);
}
' Show how to use OpenMachineConfiguration(string, string).
' It gets the machine.config file on the specified server,
' applicabe to the specified reosurce, for the specified user
' and displays section basic information. 
Shared Sub OpenMachineConfiguration4()
    ' Get the current user token.
    Dim userToken As IntPtr = _
    System.Security.Principal.WindowsIdentity.GetCurrent().Token

    ' Get the machine.config file applicabe to the
    ' specified reosurce, on the specified server for the
    ' specified user.
    Dim config As System.Configuration.Configuration = _
    WebConfigurationManager.OpenMachineConfiguration( _
    "configTest", "myServer", userToken)

    ' Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition")
    Dim i As Integer = 0
    Dim section As ConfigurationSection
    For Each section In config.Sections
        Console.WriteLine((section.SectionInformation.Name + _
        ControlChars.Tab + _
        section.SectionInformation.AllowExeDefinition.ToString()))
        i += 1
    Next section
    Console.WriteLine("[Total number of sections: {0}]", i)

    ' Display machine.config path.
    Console.WriteLine("[File path: {0}]", config.FilePath)
End Sub

Hinweise

Diese Methode wird verwendet, um mithilfe von Identitätswechsel auf eine Konfigurationsdatei zuzugreifen.

Hinweis

Das Kontotoken wird in der Regel von einer Instanz der WindowsIdentity Klasse oder über einen Aufruf an nicht verwalteten Code abgerufen, z. B. ein Aufruf an die Windows-APILogonUser. Weitere Informationen zu Aufrufen von nicht verwaltetem Code finden Sie unter Verwenden von nicht verwalteten DLL-Funktionen.

Siehe auch

Gilt für

OpenMachineConfiguration(String, String, String, String)

Öffnet die angegebene Computerkonfigurationsdatei auf dem angegebenen Server als Configuration-Objekt, um mithilfe des angegebenen Sicherheitskontexts Lese- oder Schreibvorgänge zu ermöglichen.

public:
 static System::Configuration::Configuration ^ OpenMachineConfiguration(System::String ^ locationSubPath, System::String ^ server, System::String ^ userName, System::String ^ password);
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath, string server, string userName, string password);
static member OpenMachineConfiguration : string * string * string * string -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration (locationSubPath As String, server As String, userName As String, password As String) As Configuration

Parameter

locationSubPath
String

Der Anwendungspfad, für den die Konfiguration gilt.

server
String

Der vollqualifizierte Name des Servers, dessen Konfiguration zurückgegeben werden soll.

userName
String

Der vollständige Benutzername (Domäne\Benutzer) zum Öffnen der Datei.

password
String

Das Kennwort für den Benutzernamen.

Gibt zurück

Configuration

Ein Configuration-Objekt.

Ausnahmen

Der server-Parameter oder der userName-Parameter und der password-Parameter waren ungültig.

Es konnte keine gültige Konfigurationsdatei geladen werden.

Beispiele

Im folgenden Beispiel wird gezeigt, wie Sie auf Konfigurationsinformationen mit der OpenMachineConfiguration Methode zugreifen.


// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server,
// applicabe to the specified reosurce, for the specified user
// and displays section basic information. 
static void OpenMachineConfiguration5()
{
    // Set the user id and password.
    string user =
          System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    // Substitute with actual password.
    string password = "userPassword";

    // Get the machine.config file applicabe to the
    // specified reosurce, on the specified server for the
    // specified user.
    System.Configuration.Configuration config =
        WebConfigurationManager.OpenMachineConfiguration("configTest",
        "myServer", user, password);

    // Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition");
    int i = 0;
    foreach (ConfigurationSection section in config.Sections)
    {
        Console.WriteLine(
            section.SectionInformation.Name + "\t" +
        section.SectionInformation.AllowExeDefinition);
        i += 1;
    }
    Console.WriteLine("[Total number of sections: {0}]", i);

    // Display machine.config path.
    Console.WriteLine("[File path: {0}]", config.FilePath);
}
 ' Show how to use OpenMachineConfiguration(string, string).
 ' It gets the machine.config file on the specified server,
 ' applicabe to the specified reosurce, for the specified user
 ' and displays section basic information. 
 Shared Sub OpenMachineConfiguration5()
     ' Set the user id and password.
     Dim user As String = _
     System.Security.Principal.WindowsIdentity.GetCurrent().Name
     ' Substitute with actual password.
     Dim password As String = "userPassword"

     ' Get the machine.config file applicabe to the
     ' specified reosurce, on the specified server for the
     ' specified user.
     Dim config As System.Configuration.Configuration = _
     WebConfigurationManager.OpenMachineConfiguration( _
     "configTest", "myServer", user, password)

     ' Loop to get the sections. Display basic information.
     Console.WriteLine("Name, Allow Definition")
     Dim i As Integer = 0
     Dim section As ConfigurationSection
     For Each section In config.Sections
         Console.WriteLine((section.SectionInformation.Name + _
         ControlChars.Tab + _
         section.SectionInformation.AllowExeDefinition.ToString()))
         i += 1
     Next section
     Console.WriteLine("[Total number of sections: {0}]", i)

     ' Display machine.config path.
     Console.WriteLine("[File path: {0}]", config.FilePath)
 End Sub

Hinweise

Diese Methode wird verwendet, um mithilfe von Identitätswechsel auf eine Konfigurationsdatei zuzugreifen.

Siehe auch

Gilt für