Share via


ConfigurationManager.OpenMappedMachineConfiguration Yöntem

Tanım

Makine yapılandırma dosyasını belirtilen dosya eşlemesini kullanan bir Configuration nesne olarak açar.

public:
 static System::Configuration::Configuration ^ OpenMappedMachineConfiguration(System::Configuration::ConfigurationFileMap ^ fileMap);
public static System.Configuration.Configuration OpenMappedMachineConfiguration (System.Configuration.ConfigurationFileMap fileMap);
static member OpenMappedMachineConfiguration : System.Configuration.ConfigurationFileMap -> System.Configuration.Configuration
Public Shared Function OpenMappedMachineConfiguration (fileMap As ConfigurationFileMap) As Configuration

Parametreler

fileMap
ConfigurationFileMap

Uygulama varsayılan yapılandırma dosyası yerine kullanılacak yapılandırma dosyası.

Döndürülenler

Makine yapılandırma dosyası.

Özel durumlar

Yapılandırma dosyası yüklenemedi.

Örnekler

Aşağıdaki kod örneği, yapılandırma dosyasındaki OpenMappedMachineConfiguration tüm bölümleri almak için yönteminin nasıl kullanılacağını gösterir.

   // Access the machine configuration file using mapping.
   // The function uses the OpenMappedMachineConfiguration 
   // method to access the machine configuration. 
   public static void MapMachineConfiguration()
   {
     // Get the machine.config file.
     Configuration machineConfig =
       ConfigurationManager.OpenMachineConfiguration();
     // Get the machine.config file path.
     ConfigurationFileMap configFile =
       new ConfigurationFileMap(machineConfig.FilePath);

     // Map the application configuration file to the machine 
     // configuration file.
     Configuration config =
       ConfigurationManager.OpenMappedMachineConfiguration(
         configFile);

     // Get the AppSettings section.
     AppSettingsSection appSettingSection =
       (AppSettingsSection)config.GetSection("appSettings");
     appSettingSection.SectionInformation.AllowExeDefinition =
         ConfigurationAllowExeDefinition.MachineToRoamingUser;

     // Display the configuration file sections.
     ConfigurationSectionCollection sections = 
       config.Sections;

     Console.WriteLine();
     Console.WriteLine("Using OpenMappedMachineConfiguration.");
     Console.WriteLine("Sections in machine.config:");

     // Get the sections in the machine.config.
     foreach (ConfigurationSection section in sections)
     {
         string name = section.SectionInformation.Name;
         Console.WriteLine("Name: {0}", name);
     }
   }
' Access the machine configuration file using mapping.
' The function uses the OpenMappedMachineConfiguration 
' method to access the machine configuration. 
Public Shared Sub MapMachineConfiguration()
    ' Get the machine.config file.
    Dim machineConfig As Configuration = _
        ConfigurationManager.OpenMachineConfiguration()
    ' Get the machine.config file path.
    Dim configFile _
        As New ConfigurationFileMap( _
            machineConfig.FilePath)

    ' Map the application configuration file 
    ' to the machine configuration file.
    Dim config As Configuration = _
        ConfigurationManager. _
        OpenMappedMachineConfiguration( _
            configFile)

    ' Get the AppSettings section.
    Dim appSettingSection As AppSettingsSection = _
        DirectCast(config.GetSection("appSettings"),  _
            AppSettingsSection)
    appSettingSection.SectionInformation. _
    AllowExeDefinition = _
        ConfigurationAllowExeDefinition. _
        MachineToRoamingUser

    ' Display the configuration file sections.
    Dim sections As  _
        ConfigurationSectionCollection = _
        config.Sections

    Console.WriteLine()
    Console.WriteLine( _
        "Using OpenMappedMachineConfiguration.")
    Console.WriteLine( _
        "Sections in machine.config:")

    ' Get the sections in the machine.config.
    For Each section _
        As ConfigurationSection In sections
        Dim name As String = _
            section.SectionInformation.Name
        Console.WriteLine("Name: {0}", name)
    Next

End Sub

Açıklamalar

Makine yapılandırma ayarları, yerel uygulama için geçersiz kılınmadığı sürece tüm bilgisayar ve üzerinde bulunan tüm uygulamalar için geçerlidir. Makine yapılandırma ayarları, çalışmakta olan .NET Framework sürümünün Machine.config dosyasından okunur. Machine.config dosyası aşağıdaki alt dizinde bulunur:

%windir%\Microsoft.NET\Framework\version\config

Not

Bir kaynağın Configuration nesnesini almak için kodunuzun ayarları devraldığı tüm yapılandırma dosyaları üzerinde okuma izinlerine sahip olması gerekir. Bir yapılandırma dosyasını güncelleştirmek için kodunuzun ayrıca hem yapılandırma dosyası hem de bulunduğu dizin için yazma izinlerine sahip olması gerekir. .NET Framework bilgisayarda yüklü olabilecek diğer sürümleri için Machine.config dosyasına erişmek mümkün değildir.

Şunlara uygulanır

Ayrıca bkz.