WebConfigurationManager.OpenMachineConfiguration Methode

Definitie

Hiermee opent u het computerconfiguratiebestand als een Configuration object om lees- of schrijfbewerkingen toe te staan.

Overloads

Name Description
OpenMachineConfiguration()

Hiermee opent u het computerconfiguratiebestand op de huidige computer als een Configuration object om lees- of schrijfbewerkingen toe te staan.

OpenMachineConfiguration(String)

Hiermee opent u het computerconfiguratiebestand op de huidige computer als een Configuration object om lees- of schrijfbewerkingen toe te staan.

OpenMachineConfiguration(String, String)

Hiermee opent u het opgegeven computerconfiguratiebestand op de opgegeven server als een Configuration object om lees- of schrijfbewerkingen toe te staan.

OpenMachineConfiguration(String, String, IntPtr)

Hiermee opent u het opgegeven computerconfiguratiebestand op de opgegeven server als een Configuration object, met behulp van de opgegeven beveiligingscontext om lees- of schrijfbewerkingen toe te staan.

OpenMachineConfiguration(String, String, String, String)

Hiermee opent u het opgegeven computerconfiguratiebestand op de opgegeven server als een Configuration object, met behulp van de opgegeven beveiligingscontext om lees- of schrijfbewerkingen toe te staan.

OpenMachineConfiguration()

Hiermee opent u het computerconfiguratiebestand op de huidige computer als een Configuration object om lees- of schrijfbewerkingen toe te staan.

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

Retouren

Een Configuration-object.

Uitzonderingen

Er kan geen geldig configuratiebestand worden geladen.

Voorbeelden

In het volgende voorbeeld ziet u hoe u met de OpenMachineConfiguration methode toegang hebt tot configuratiegegevens.


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

Opmerkingen

De OpenMachineConfiguration methode opent het computerconfiguratiebestand op de computer waarop de toepassing wordt uitgevoerd. Dit bestand bevindt zich in de standaard buildmap %windir%\Microsoft.NET\Framework\version\config.

Zie ook

Van toepassing op

OpenMachineConfiguration(String)

Hiermee opent u het computerconfiguratiebestand op de huidige computer als een Configuration object om lees- of schrijfbewerkingen toe te staan.

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

Parameters

locationSubPath
String

Het toepassingspad waarop de computerconfiguratie 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 OpenMachineConfiguration methode toegang hebt tot configuratiegegevens.


// Show how to use OpenMachineConfiguration(string).
// It gets the machine.config file applicable to the
// specified resource and displays section
// basic information.
static void OpenMachineConfiguration2()
{
    // Get the machine.config file applicable to the
    // specified resource.
    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

Opmerkingen

Met deze methode wordt het computerconfiguratiebestand geopend dat van toepassing is op de map die is opgegeven door de locationSubPath parameter.

Zie ook

Van toepassing op

OpenMachineConfiguration(String, String)

Hiermee opent u het opgegeven computerconfiguratiebestand op de opgegeven server als een Configuration object om lees- of schrijfbewerkingen toe te staan.

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

Parameters

locationSubPath
String

Het toepassingspad waarop de configuratie van toepassing is.

server
String

De volledig gekwalificeerde naam van de server waarvoor de configuratie moet worden geretourneerd.

Retouren

Een Configuration-object.

Uitzonderingen

Er kan geen geldig configuratiebestand worden geladen.

Voorbeelden

In het volgende voorbeeld ziet u hoe u met de OpenMachineConfiguration methode toegang hebt tot configuratiegegevens.


// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server and
// applicable to the specified resource and displays section
// basic information.
static void OpenMachineConfiguration3()
{
    // Get the machine.config file applicable to the
    // specified resource 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

Opmerkingen

Met deze methode opent u het computerconfiguratiebestand dat zich in de map bevindt die is opgegeven door de locationSubPath parameter en op de computer die is opgegeven door de server parameter.

Zie ook

Van toepassing op

OpenMachineConfiguration(String, String, IntPtr)

Hiermee opent u het opgegeven computerconfiguratiebestand op de opgegeven server als een Configuration object, met behulp van de opgegeven beveiligingscontext om lees- of schrijfbewerkingen toe te staan.

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

Parameters

locationSubPath
String

Het toepassingspad waarop de configuratie van toepassing is.

server
String

De volledig gekwalificeerde naam van de server waarvoor de configuratie moet worden geretourneerd.

userToken
IntPtr

nativeint

Een accounttoken dat moet worden gebruikt.

Retouren

Een Configuration-object.

Uitzonderingen

Geldige waarden zijn niet opgegeven voor de server of userToken parameters.

Er kan geen geldig configuratiebestand worden geladen.

Voorbeelden

In het volgende voorbeeld ziet u hoe u met de OpenMachineConfiguration methode toegang hebt tot configuratiegegevens.


// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server,
// applicable to the specified resource, 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 applicable to the
    // specified resource, 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

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.

Zie ook

Van toepassing op

OpenMachineConfiguration(String, String, String, String)

Hiermee opent u het opgegeven computerconfiguratiebestand op de opgegeven server als een Configuration object, met behulp van de opgegeven beveiligingscontext om lees- of schrijfbewerkingen toe te staan.

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

Parameters

locationSubPath
String

Het toepassingspad waarop de configuratie van toepassing is.

server
String

De volledig gekwalificeerde naam van de server waarvoor de configuratie moet worden geretourneerd.

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.

Er kan geen geldig configuratiebestand worden geladen.

Voorbeelden

In het volgende voorbeeld ziet u hoe u met de OpenMachineConfiguration methode toegang hebt tot configuratiegegevens.


// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server,
// applicable to the specified resource, 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 applicable to the
    // specified resource, 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

Opmerkingen

Deze methode wordt gebruikt voor toegang tot een configuratiebestand met behulp van imitatie.

Zie ook

Van toepassing op