ConfigurationLocation 类

定义

表示配置文件中的 location 元素。Represents a location element within a configuration file.

public ref class ConfigurationLocation
public class ConfigurationLocation
type ConfigurationLocation = class
Public Class ConfigurationLocation
继承
ConfigurationLocation

示例

在下面的代码示例中,加载了应用程序的 Web 配置 MySampleApp ,并显示了配置中定义的位置。In the following code example, the Web configuration for the application MySampleApp is loaded, and then the locations defined in the configuration are displayed.

using System;
using System.Collections;
using System.Configuration;

class DisplayLocationInfo
{
    static void Main(string[] args)
    {
        Configuration config = 
            ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        ConfigurationLocationCollection myLocationCollection = config.Locations;
        foreach (ConfigurationLocation myLocation in myLocationCollection)
        {
            Console.WriteLine("Location Path: {0}", myLocation.Path);
            Configuration myLocationConfiguration = myLocation.OpenConfiguration();
            Console.WriteLine("Location Configuration File Path: {0}",
                myLocationConfiguration.FilePath);
        }
        Console.WriteLine("Done...");
        Console.ReadLine();
    }
}
Imports System.Collections
Imports System.Configuration

Class DisplayLocationInfo
    Public Overloads Shared Sub Main()
        Dim config As System.Configuration.Configuration = _
            ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
        Dim myLocationCollection As _
            System.Configuration.ConfigurationLocationCollection = config.Locations
        Dim myLocation As ConfigurationLocation
        For Each myLocation In  myLocationCollection
            Console.WriteLine("Location Path: {0}", myLocation.Path)
            Dim myLocationConfiguration As System.Configuration.Configuration = _
                myLocation.OpenConfiguration()
            Console.WriteLine("Location Configuration Path: {0}", _
                myLocationConfiguration.FilePath)
        Next myLocation
        Console.WriteLine("Done...")
        Console.ReadLine()
    End Sub
End Class

注解

类的实例 ConfigurationLocation 表示 location 配置文件中的单个元素。An instance of the ConfigurationLocation class represents a single location element within a configuration file. 位置用于指定仅适用于 Web 应用程序中的指定资源(如特定页面、文件或子目录)的配置设置。Locations are used to specify configuration settings that apply only to a specified resource, such as a specific page, file, or subdirectory, within your Web application. 使用 ConfigurationLocation 类可获取应用于指定资源的路径和 Configuration 对象。Use the ConfigurationLocation class to obtain the path and the Configuration object that applies to the specified resource.

属性

Path

获取配置设置由此 ConfigurationLocation 对象表示的资源的相对路径。Gets the relative path to the resource whose configuration settings are represented by this ConfigurationLocation object.

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OpenConfiguration()

创建 Configuration 对象的实例。Creates an instance of a Configuration object.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于