Uri Uri Uri Uri Class

定义

提供统一资源标识符 (URI) 的对象表示形式和对 URI 各部分的轻松访问。Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.

public ref class Uri : System::Runtime::Serialization::ISerializable
[System.ComponentModel.TypeConverter(typeof(System.UriTypeConverter))]
[System.Serializable]
public class Uri : System.Runtime.Serialization.ISerializable
type Uri = class
    interface ISerializable
Public Class Uri
Implements ISerializable
继承
属性
实现

示例

下面的示例创建的实例Uri类,并使用它来创建WebRequest实例。The following example creates an instance of the Uri class and uses it to create a WebRequest instance.

Uri^ siteUri = gcnew Uri( "http://www.contoso.com/" );
WebRequest^ wr = WebRequest::Create( siteUri );
Uri siteUri = new Uri("http://www.contoso.com/");
 
WebRequest wr = WebRequest.Create(siteUri);

Dim siteUri As New Uri("http://www.contoso.com/")
        
Dim wr As WebRequest = WebRequest.Create(siteUri)

注解

URI 是可用于在 intranet 或 Internet 上的应用程序资源的简洁表示形式。A URI is a compact representation of a resource available to your application on the intranet or Internet. Uri类定义的属性和方法来处理 Uri,包括分析、 比较和合并。The Uri class defines the properties and methods for handling URIs, including parsing, comparing, and combining. Uri类属性是只读的; 若要创建一个可修改的对象,使用UriBuilder类。The Uri class properties are read-only; to create a modifiable object, use the UriBuilder class.

相对 Uri (例如,"/ new/index.htm"),以便它们绝对必须展开相对于基 URI。Relative URIs (for example, "/new/index.htm") must be expanded with respect to a base URI so that they are absolute. MakeRelative方法提供要转换为在必要时的相对 Uri 的绝对 Uri。The MakeRelative method is provided to convert absolute URIs to relative URIs when necessary.

Uri构造函数字符串是否格式正确的 URI,包括方案标识符未转义 URI 字符串。The Uri constructors do not escape URI strings if the string is a well-formed URI including a scheme identifier.

Uri属性返回规范化数据表示形式中转义的编码,其中包含所有字符 Unicode 值大于 127 替换为其十六进制等效项。The Uri properties return a canonical data representation in escaped encoding, with all characters with Unicode values greater than 127 replaced with their hexadecimal equivalents. 为使采用规范格式的 URIUri构造函数将执行以下步骤:To put the URI in canonical form, the Uri constructor performs the following steps:

  • 将 URI 方案转换为小写。Converts the URI scheme to lowercase.

  • 将主机名转换为小写。Converts the host name to lowercase.

  • 如果主机名是 IPv6 地址,则使用规范的 IPv6 地址。If the host name is an IPv6 address, the canonical IPv6 address is used. 删除 ScopeId 和其他可选的 IPv6 数据。ScopeId and other optional IPv6 data are removed.

  • 删除默认值和空的端口号。Removes default and empty port numbers.

  • 将隐式文件路径,而无需 file:// 方案 (例如,"C:\my\file") 转换为显式文件路径的 file:// 方案。Converts implicit file paths without the file:// scheme (for example, "C:\my\file") to explicit file paths with the file:// scheme.

  • 没有保留的用途的转义的字符 (也称为百分比编码八位字节) 为解码状态 (也称为进行转义的情况)。Escaped characters (also known as percent-encoded octets) that don't have a reserved purpose are decoded (also known as being unescaped). 这些非保留的字符包括大写和小写字母 (%41-%5a 和 %61-%7a)、 小数位数 (%30-%39)、 连字符 (%2d)、 句点 (%2e) 下划线 (%5f) 和颚化符 (%7e)。These unreserved characters include uppercase and lowercase letters (%41-%5A and %61-%7A), decimal digits (%30-%39), hyphen (%2D), period (%2E), underscore (%5F), and tilde (%7E).

  • Canonicalizes 路径的分层 Uri 由压缩序列如 /。 /.../,和 / / (是否转义序列)。Canonicalizes the path for hierarchical URIs by compacting sequences such as /./, /../, and // (whether or not the sequence is escaped). 请注意,有不压缩这些序列的一些方案。Note that there are some schemes for which these sequences are not compacted.

  • 用于分层 Uri 时,如果主机未终止以正斜杠 (/),则添加一个。For hierarchical URIs, if the host is not terminated with a forward slash (/), one is added.

  • 默认情况下,根据 RFC 2396 转义的 URI 中的任何保留的字符。By default, any reserved characters in the URI are escaped in accordance with RFC 2396. 此行为更改如果国际资源标识符或国际域名分析启用了在 URI 中的保留字符进行转义根据 RFC 3986 和 RFC 3987。This behavior changes if International Resource Identifiers or International Domain Name parsing is enabled in which case reserved characters in the URI are escaped in accordance with RFC 3986 and RFC 3987.

作为某些方案、 点段和空段的构造函数中的规范化的一部分 (/。 /.../,和 / /) 压缩的 (即,删除了)。As part of canonicalization in the constructor for some schemes, dot-segments and empty segments (/./, /../, and //) are compacted (in other words, they are removed). URI 将为其压缩这些序列的方案包括 http、 https、 tcp、 net.pipe 和 net.tcp。The schemes for which URI will compact these sequences include http, https, tcp, net.pipe, and net.tcp. 对于其他方案,这些序列不会进行压缩。For some other schemes, these sequences are not compacted. 下面是在实践中的此压缩外观。Here's how this compacting looks in practice.

var uri = new Uri("http://myUrl/../.."); // http scheme, unescaped
OR
var uri = new Uri("http://myUrl/%2E%2E/%2E%2E"); // http scheme, escaped
OR
var uri = new Uri("ftp://myUrl/../.."); // ftp scheme, unescaped
OR
var uri = new Uri("ftp://myUrl/%2E%2E/%2E%2E"); // ftp scheme, escaped

Console.WriteLine(uri.AbsoluteUri);  
Console.WriteLine(uri.PathAndQuery);  

此代码执行时,它返回以下输出,如有必要进行非转义,然后压缩的转义序列。When this code is executed, it returns the following output, with the escaped sequences unescaped if necessary and then compacted.

http://myUrl/  
/  

可以将转换的内容Uri类从与可读的 URI 引用通过使用编码的转义 URI 引用ToString方法。You can transform the contents of the Uri class from an escape encoded URI reference to a readable URI reference by using the ToString method. 请注意,可能仍保留的某些字符进行转义的输出中ToString方法。Note that some reserved characters might still be escaped in the output of the ToString method. 这是为了支持从返回的值的 URI 的明确重新构造ToStringThis is to support unambiguous reconstruction of a URI from the value returned by ToString.

某些 Uri 包含片段标识符和/或查询。Some URIs include a fragment identifier or a query or both. 片断标识符是任何文本,跟在数字符号 (#),不包括数字符号;片段文本存储在Fragment属性。A fragment identifier is any text that follows a number sign (#), not including the number sign; the fragment text is stored in the Fragment property. 查询信息是遵循 URI; 中为问号 (?) 的任何文本查询文本将存储在Query属性。Query information is any text that follows a question mark (?) in the URI; the query text is stored in the Query property.

.NET Framework 版本 1.1 中,如果构造函数指定的字符串包含未知的方案中和"c:\",Uri 类插入"/ /"冒号后面。In the .NET Framework version 1.1, if the string specified to a constructor contains an unknown scheme and "c:\", the Uri class inserts "//" after the colon. 例如,URIxyz:c:\abc转换为xyz://c:/abcFor example, the URI xyz:c:\abc is converted to xyz://c:/abc. 在.NET Framework 2.0 版中,此行为已被删除,并且示例字符串转换为xyz:c:/abcIn the .NET Framework version 2.0, this behavior has been removed, and the example string is converted to xyz:c:/abc.

备注

URI 类支持 IPv4 协议的两个四组表示法和冒号十六进制的 IPv6 协议中使用的 IP 地址。The URI class supports the use of IP addresses in both quad-notation for IPv4 protocol and colon-hexadecimal for IPv6 protocol. 请记住将 IPv6 地址括在方括号内,如下所示 http://[::1]。Remember to enclose the IPv6 address in square brackets, as in http://[::1].

国际资源标识符支持International Resource Identifier Support

Web 地址通常表示使用统一资源标识符构成的一组非常有限的字符:Web addresses are typically expressed using uniform resource identifiers that consist of a very restricted set of characters:

  • 英文字母表中的大小写 ASCII 字母。Upper and lower case ASCII letters from the English alphabet.

  • 从 0 到 9 的数字。Digits from 0 to 9.

  • 少量的其他 ASCII 符号。A small number of other ASCII symbols.

Uri 的规范记录在 RFC 2396、 RFC 2732、 RFC 3986 和 RFC 3987 发布 Internet 工程任务组 (IETF) 中。The specifications for URIs are documented in RFC 2396, RFC 2732, RFC 3986, and RFC 3987 published by the Internet Engineering Task Force (IETF).

随着 Internet 的发展,越来越需要使用英语以外的语言识别资源。With the growth of the Internet, there is a growing need to identify resources using languages other than English. 标识符满足了这种需求,并且使得非 ASCII 字符(Unicode 中的字符/ISO 10646 字符集)被称为国际资源标识符(IRI)。Identifiers which facilitate this need and allow non-ASCII characters (characters in the Unicode/ISO 10646 character set) are known as International Resource Identifiers (IRIs). IETF 发布的 RFC 3987 记录了 IRI 的规格。The specifications for IRIs are documented in RFC 3987 published by IETF. 使用 IRI 允许 URL 包含 Unicode 字符。Using IRIs allows a URL to contain Unicode characters.

现有Uri类进行了扩展在.NET Framework 3.5 版,3.0 SP1 和 2.0 SP1 提供 IRI 支持根据 RFC 3987。The existing Uri class has been extended in .NET Framework v3.5, 3.0 SP1, and 2.0 SP1 to provide IRI support based on RFC 3987. 除非他们专门启用 IRI,.NET Framework 版本 4.5 之前的版本中的用户不会从.NET Framework 2.0 行为的任何更改。Users of .NET Framework versions before version 4.5 will not see any change from the .NET Framework 2.0 behavior unless they specifically enable IRI. 这确保了 NET Framework 以前版本的应用程序兼容性。This ensures application compatibility with prior versions of the .NET Framework.

若要启用 IRI 支持,则需要以下更改:To enable support for IRI, the following change is required:

  • 指定是否对域名应用国际化域名 (IDN) 分析以及是否应该应用 IRI 分析规则。Specify whether you want Internationalized Domain Name (IDN) parsing applied to the domain name and whether IRI parsing rules should be applied. 这可以实现machine.config中或在app.config文件。This can be done in the machine.config or in the app.config file. 例如,添加以下代码:For example, add the following:

    <configuration>  
      <uri>  
      <idn enabled="All" />  
      <iriParsing enabled="true" />  
      </uri>  
    </configuration>  
    

.NET Framework 4.5 和更高版本的用户始终拥有启用 IRI。Users of .NET Framework 4.5 and newer always have IRI enabled. IRI 分析不能更改使用 .config文件。IRI parsing cannot be changed using a .config file.

启用 IDN 可以将域名中所有 Unicode 标签转换成标签的 Punycode 等同项。Enabling IDN will convert all Unicode labels in a domain name to their Punycode equivalents. Punycode 名称只包含 ASCII 字符,并且始终以 xn-- 前缀开头。Punycode names contain only ASCII characters and always start with the xn-- prefix. 这样是为了支持 Internet 上的 DNS 服务器,因为大部分 DNS 服务器仅支持 ASCII 字符(参见 RFC 3940)。The reason for this is to support existing DNS servers on the Internet, since most DNS servers only support ASCII characters (see RFC 3940).

启用 IRI 和 IDN 会影响 Uri.DnsSafeHost 属性的值。Enabling IRI and IDN affects the value of the Uri.DnsSafeHost property. 启用 IRI 和 IDN 还可能更改 EqualsOriginalStringGetComponentsIsWellFormedOriginalString 方法的行为。Enabling IRI and IDN can also change the behavior of the Equals, OriginalString, GetComponents, and IsWellFormedOriginalString methods.

有三个可能的 IDN 值具体取决于使用的 DNS 服务器:There are three possible values for IDN depending on the DNS servers that are used:

  • 启用 idn = Allidn enabled = All

    此值会将所有 Unicode 域名转换为它们的 Punycode 等效项(IDN 名称)。This value will convert any Unicode domain names to their Punycode equivalents (IDN names).

  • 启用 idn = AllExceptIntranetidn enabled = AllExceptIntranet

    此值会将不在使用 Punycode 等效项 (IDN 名称) 在本地 Intranet 上的所有 Unicode 域名都转换。This value will convert all Unicode domain names not on the local Intranet to use the Punycode equivalents (IDN names). 在这种情况下若要处理本地 Intranet 上的国际化名称,用于 Intranet 的 DNS 服务器应该支持 Unicode 名称解析。In this case to handle international names on the local Intranet, the DNS servers that are used for the Intranet should support Unicode name resolution.

  • 启用 idn = 无idn enabled = None

    此值不会将任何 Unicode 域名转换为使用 Punycode。This value will not convert any Unicode domain names to use Punycode. 这是默认值是与.NET Framework 2.0 行为一致。This is the default value which is consistent with the .NET Framework 2.0 behaviour.

当启用 IRI 分析 (iriParsing 启用 = true) 根据 RFC 3986 和 RFC 3987 中的最新 IRI 规则执行规范化和字符检查。When IRI parsing is enabled (iriParsing enabled = true) normalization and character checking are done according to the latest IRI rules in RFC 3986 and RFC 3987. 禁用 IRI 分析后,规范化和字符检查会根据 RFC 2396 和 RFC 2732 (对执行 IPv6 文本)。When IRI parsing is disabled, normalization and character checking are performed according to RFC 2396 and RFC 2732 (for IPv6 literals). 在.NET Framework 版本 4.5 之前的版本中,默认值是falseIn versions of the .NET Framework before version 4.5, the default value is false. 在.NET Framework 4.5 和更高版本中,默认值是true,并且不能由中设置修改的 IRI 分析的启用的状态 .config文件。In .NET Framework version 4.5 and newer, the default value is true, and the enabled state of IRI parsing cannot be modified by settings in a .config file.

IRI 和 IDN 中处理Uri还可以使用控制类System.Configuration.IriParsingElementSystem.Configuration.IdnElement,和System.Configuration.UriSection配置设置类。IRI and IDN processing in the Uri class can also be controlled using the System.Configuration.IriParsingElement, System.Configuration.IdnElement, and System.Configuration.UriSection configuration setting classes. System.Configuration.IriParsingElement 设置启用或禁用 Uri 类中的 IRI 处理。The System.Configuration.IriParsingElement setting enables or disables IRI processing in the Uri class. System.Configuration.IdnElement 设置启用或禁用 Uri 类中的 IDN 处理。The System.Configuration.IdnElement setting enables or disables IDN processing in the Uri class. System.Configuration.IriParsingElement 也可间接控制 IDN。The System.Configuration.IriParsingElement setting also indirectly controls IDN. 必须启用 IRI 处理才能进行 IDN 处理。IRI processing must be enabled for IDN processing to be possible. 如果禁用 IRI,IDN 处理将被设置为默认值,这时 NET Framework 2.0 行为用于兼容性,并且 IDN 名称不可用。If IRI processing is disabled, then IDN processing will be set to the default setting where the .NET Framework 2.0 behavior is used for compatibility and IDN names are not used.

配置设置System.Configuration.IriParsingElementSystem.Configuration.IdnElement将读取一次时第一个System.Uri构造类。The configuration setting for the System.Configuration.IriParsingElement and System.Configuration.IdnElement will be read once when the first System.Uri class is constructed. 忽略时间后更改为默认设置。Changes to configuration settings after that time are ignored.

System.GenericUriParser 类已得到扩展,允许创建支持 IRI 和 IDN 的自定义分析。The System.GenericUriParser class has also been extended to allow creating a customizable parser that supports IRI and IDN. 通过将枚举中可用值的按位组合传递给 System.GenericUriParserOptions 构造函数 System.GenericUriParser 来指定 System.GenericUriParser 对象的行为。The behavior of a System.GenericUriParser object is specified by passing a bitwise combination of the values available in the System.GenericUriParserOptions enumeration to the System.GenericUriParser constructor. GenericUriParserOptions.IriParsing 类型表示分析程序支持 RFC 3987 中为国际资源标识符 (IRI) 指定的分析规则。The GenericUriParserOptions.IriParsing type indicates the parser supports the parsing rules specified in RFC 3987 for International Resource Identifiers (IRI). 是否使用 IRI 由前面讨论的配置值指定。Whether IRI is used is dictated by the configuration values previously discussed.

GenericUriParserOptions.Idn 类型表示分析程序支持主机名的国际化域名 (IDN) 分析。The GenericUriParserOptions.Idn type indicates the parser supports Internationalized Domain Name (IDN) parsing (IDN) of host names. 是否使用 IDN 由前面讨论的配置值指定。Whether IDN is used is dictated by the configuration values previously discussed.

隐式文件路径支持Implicit File Path Support

Uri 此外可以用于表示本地文件系统路径。Uri can also be used to represent local file system paths. 这些路径可以表示显式file:// 方案开头的 Uri 中并隐式中没有的 file:// 方案的 Uri。These paths can be represented explicitly in URIs that begin with the file:// scheme, and implicitly in URIs that do not have the file:// scheme. 作为一个具体示例,以下两个 Uri 都是有效,并表示相同的文件路径:As a concrete example, the following two URIs are both valid, and represent the same file path:

Uri uri1 = new Uri("C:/test/path/file.txt") // Implicit file path.
Uri uri2 = new Uri("file:///C:/test/path/file.txt") // Explicit file path.

这些隐式文件路径不符合 URI 规范,因此应避免在可能的情况。These implicit file paths are not compliant with the URI specification and so should be avoided when possible. 如果使用基于 Unix 的系统上的.NET Core,隐式文件路径尤其是有问题,由于可以隐式的绝对文件路径是无法区分从相对路径。When using .NET Core on Unix-based systems, implicit file paths can be especially problematic, because an absolute implicit file path is indistinguishable from a relative path. 时就可能出现,这种多义性Uri默认为解释为绝对 URI 的路径。When such ambiguity is present, Uri default to interpreting the path as an absolute URI.

性能注意事项Performance Considerations

如果使用 *Web.config * 处理 Uri,如果其方案标识符使用了非标准所需的文件,其中包含 Uri 来初始化应用程序、 其他时间。If you use a *Web.config *file that contains URIs to initialize your application, additional time is required to process the URIs if their scheme identifiers are nonstandard. 在这种情况下,当需要 Uri 时,不是在启动时初始化应用程序的受影响的部分。In such a case, initialize the affected parts of your application when the URIs are needed, not at start time.

调用方说明

出于安全考虑,您的应用程序时应小心接受Uri来自不受信任的源和使用的实例dontEscape设置为true。可以通过调用检查有效性的 URI 字符串IsWellFormedOriginalString()方法。Because of security concerns, your application should use caution when accepting Uri instances from untrusted sources and with dontEscape set to true.You can check a URI string for validity by calling the IsWellFormedOriginalString() method.

构造函数

Uri(SerializationInfo, StreamingContext) Uri(SerializationInfo, StreamingContext) Uri(SerializationInfo, StreamingContext) Uri(SerializationInfo, StreamingContext)

UriSerializationInfo 类的指定实例初始化 StreamingContext 类的新实例。Initializes a new instance of the Uri class from the specified instances of the SerializationInfo and StreamingContext classes.

Uri(String) Uri(String) Uri(String) Uri(String)

用指定的 URI 初始化 Uri 类的新实例。Initializes a new instance of the Uri class with the specified URI.

Uri(String, Boolean) Uri(String, Boolean) Uri(String, Boolean) Uri(String, Boolean)

用指定的 URI 初始化 Uri 类的新实例,并对字符转义进行显式控制。Initializes a new instance of the Uri class with the specified URI, with explicit control of character escaping.

Uri(String, UriKind) Uri(String, UriKind) Uri(String, UriKind) Uri(String, UriKind)

用指定的 URI 初始化 Uri 类的新实例。Initializes a new instance of the Uri class with the specified URI. 此构造函数允许指定 URI 字符串是相对 URI、绝对 URI 还是不确定。This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate.

Uri(Uri, String) Uri(Uri, String) Uri(Uri, String) Uri(Uri, String)

根据指定的基 URI 和相对 URI 字符串,初始化 Uri 类的新实例。Initializes a new instance of the Uri class based on the specified base URI and relative URI string.

Uri(Uri, String, Boolean) Uri(Uri, String, Boolean) Uri(Uri, String, Boolean) Uri(Uri, String, Boolean)

根据指定的基 URI 和相对 URI,初始化 Uri 类的新实例,并对字符转义进行显式控制。Initializes a new instance of the Uri class based on the specified base and relative URIs, with explicit control of character escaping.

Uri(Uri, Uri) Uri(Uri, Uri) Uri(Uri, Uri) Uri(Uri, Uri)

根据指定的基 Uri 实例和相对 Uri 实例的组合,初始化 Uri 类的新实例。Initializes a new instance of the Uri class based on the combination of a specified base Uri instance and a relative Uri instance.

字段

SchemeDelimiter SchemeDelimiter SchemeDelimiter SchemeDelimiter

指定将通讯协议方案同 URI 的地址部分分开的字符。Specifies the characters that separate the communication protocol scheme from the address portion of the URI. 此字段为只读。This field is read-only.

UriSchemeFile UriSchemeFile UriSchemeFile UriSchemeFile

指定 URI 是指向文件的指针。Specifies that the URI is a pointer to a file. 此字段为只读。This field is read-only.

UriSchemeFtp UriSchemeFtp UriSchemeFtp UriSchemeFtp

指定通过文件传输协议 (FTP) 访问 URI。Specifies that the URI is accessed through the File Transfer Protocol (FTP). 此字段为只读。This field is read-only.

UriSchemeGopher UriSchemeGopher UriSchemeGopher UriSchemeGopher

指定通过 Gopher 协议访问 URI。Specifies that the URI is accessed through the Gopher protocol. 此字段为只读。This field is read-only.

UriSchemeHttp UriSchemeHttp UriSchemeHttp UriSchemeHttp

指定通过超文本传输协议 (HTTP) 访问 URI。Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). 此字段为只读。This field is read-only.

UriSchemeHttps UriSchemeHttps UriSchemeHttps UriSchemeHttps

指定通过安全超文本传输协议 (HTTPS) 访问 URI。Specifies that the URI is accessed through the Secure Hypertext Transfer Protocol (HTTPS). 此字段为只读。This field is read-only.

UriSchemeMailto UriSchemeMailto UriSchemeMailto UriSchemeMailto

指定 URI 是一个电子邮件地址,需通过简单邮件传输协议 (SMTP) 访问。Specifies that the URI is an email address and is accessed through the Simple Mail Transport Protocol (SMTP). 此字段为只读。This field is read-only.

UriSchemeNetPipe UriSchemeNetPipe UriSchemeNetPipe UriSchemeNetPipe

指明通过 Windows Communication Foundation (WCF) 使用的 NetPipe 方案访问该 URI。Specifies that the URI is accessed through the NetPipe scheme used by Windows Communication Foundation (WCF). 此字段为只读。This field is read-only.

UriSchemeNetTcp UriSchemeNetTcp UriSchemeNetTcp UriSchemeNetTcp

指明通过 Windows Communication Foundation (WCF) 使用的 NetTcp 方案访问该 URI。Specifies that the URI is accessed through the NetTcp scheme used by Windows Communication Foundation (WCF). 此字段为只读。This field is read-only.

UriSchemeNews UriSchemeNews UriSchemeNews UriSchemeNews

指定 URI 是 Internet 新闻组,而且可以通过 Network 新闻传输协议 (NNTP) 进行访问。Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). 此字段为只读。This field is read-only.

UriSchemeNntp UriSchemeNntp UriSchemeNntp UriSchemeNntp

指定 URI 是 Internet 新闻组,而且可以通过 Network 新闻传输协议 (NNTP) 进行访问。Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). 此字段为只读。This field is read-only.

属性

AbsolutePath AbsolutePath AbsolutePath AbsolutePath

获取 URI 的绝对路径。Gets the absolute path of the URI.

AbsoluteUri AbsoluteUri AbsoluteUri AbsoluteUri

获取绝对 URI。Gets the absolute URI.

Authority Authority Authority Authority

获取服务器的域名系统 (DNS) 主机名或 IP 地址和端口号。Gets the Domain Name System (DNS) host name or IP address and the port number for a server.

DnsSafeHost DnsSafeHost DnsSafeHost DnsSafeHost

获得可安全用于 DNS 解析的未转义主机名(如必要)。Gets a host name that, after being unescaped if necessary, is safe to use for DNS resolution.

Fragment Fragment Fragment Fragment

获取转义 URI 片段。Gets the escaped URI fragment.

Host Host Host Host

获取此实例的主机部分。Gets the host component of this instance.

HostNameType HostNameType HostNameType HostNameType

获取 URI 中指定的主机名的类型。Gets the type of the host name specified in the URI.

IdnHost IdnHost IdnHost IdnHost

RFC 3490 根据需要使用 Punycode,符合主机的国际域名要求。The RFC 3490 compliant International Domain Name of the host, using Punycode as appropriate. 该字符串在不进行转义的情况下(如必要)可安全用于 DNS 解析。This string, after being unescaped if necessary, is safe to use for DNS resolution.

IsAbsoluteUri IsAbsoluteUri IsAbsoluteUri IsAbsoluteUri

获取一个值,该值指示 Uri 实例是否为绝对 URI。Gets whether the Uri instance is absolute.

IsDefaultPort IsDefaultPort IsDefaultPort IsDefaultPort

获取一个值,该值指示 URI 的端口值是否为此方案的默认值。Gets whether the port value of the URI is the default for this scheme.

IsFile IsFile IsFile IsFile

获取一个值,该值指示指定的 Uri 是否为文件 URI。Gets a value indicating whether the specified Uri is a file URI.

IsLoopback IsLoopback IsLoopback IsLoopback

获取一个值,该值指示指定的 Uri 是否引用了本地主机。Gets whether the specified Uri references the local host.

IsUnc IsUnc IsUnc IsUnc

获取一个值,该值指示指定的 Uri 是否为统一命名约定 (UNC) 路径。Gets whether the specified Uri is a universal naming convention (UNC) path.

LocalPath LocalPath LocalPath LocalPath

获取文件名的本地操作系统表示形式。Gets a local operating-system representation of a file name.

OriginalString OriginalString OriginalString OriginalString

获取传递给 Uri 构造函数的原始 URI 字符串。Gets the original URI string that was passed to the Uri constructor.

PathAndQuery PathAndQuery PathAndQuery PathAndQuery

获取用问号 (?) 分隔的 AbsolutePathQuery 属性。Gets the AbsolutePath and Query properties separated by a question mark (?).

Port Port Port Port

获取此 URI 的端口号。Gets the port number of this URI.

Query Query Query Query

获取指定 URI 中包括的任何查询信息。Gets any query information included in the specified URI.

Scheme Scheme Scheme Scheme

获取此 URI 的方案名称。Gets the scheme name for this URI.

Segments Segments Segments Segments

获取包含构成指定 URI 的路径段的数组。Gets an array containing the path segments that make up the specified URI.

UserEscaped UserEscaped UserEscaped UserEscaped

指示 URI 字符串在创建 Uri 实例之前已被完全转义。Indicates that the URI string was completely escaped before the Uri instance was created.

UserInfo UserInfo UserInfo UserInfo

获取用户名、密码或其他与指定 URI 关联的特定于用户的信息。Gets the user name, password, or other user-specific information associated with the specified URI.

方法

Canonicalize() Canonicalize() Canonicalize() Canonicalize()

将内部存储的 URI 转换为规范化格式。Converts the internally stored URI to canonical form.

CheckHostName(String) CheckHostName(String) CheckHostName(String) CheckHostName(String)

确定指定的主机名是否为有效的 DNS 名称。Determines whether the specified host name is a valid DNS name.

CheckSchemeName(String) CheckSchemeName(String) CheckSchemeName(String) CheckSchemeName(String)

确定指定的方案名是否有效。Determines whether the specified scheme name is valid.

CheckSecurity() CheckSecurity() CheckSecurity() CheckSecurity()

调用此方法不起任何作用。Calling this method has no effect.

Compare(Uri, Uri, UriComponents, UriFormat, StringComparison) Compare(Uri, Uri, UriComponents, UriFormat, StringComparison) Compare(Uri, Uri, UriComponents, UriFormat, StringComparison) Compare(Uri, Uri, UriComponents, UriFormat, StringComparison)

使用指定的比较规则比较两个 URI 的指定部分。Compares the specified parts of two URIs using the specified comparison rules.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

比较两个 Uri 实例是否相等。Compares two Uri instances for equality.

Escape() Escape() Escape() Escape()

将路径部分中的任何不安全字符或保留字符转换为对应的十六进制字符表示形式。Converts any unsafe or reserved characters in the path component to their hexadecimal character representations.

EscapeDataString(String) EscapeDataString(String) EscapeDataString(String) EscapeDataString(String)

将字符串转换为它的转义表示形式。Converts a string to its escaped representation.

EscapeString(String) EscapeString(String) EscapeString(String) EscapeString(String)

将字符串转换为它的转义表示形式。Converts a string to its escaped representation.

EscapeUriString(String) EscapeUriString(String) EscapeUriString(String) EscapeUriString(String)

将 URI 字符串转换为它的转义表示形式。Converts a URI string to its escaped representation.

FromHex(Char) FromHex(Char) FromHex(Char) FromHex(Char)

获取十六进制数字的十进制值。Gets the decimal value of a hexadecimal digit.

GetComponents(UriComponents, UriFormat) GetComponents(UriComponents, UriFormat) GetComponents(UriComponents, UriFormat) GetComponents(UriComponents, UriFormat)

使用特殊字符的指定转义,获取当前实例的指定部分。Gets the specified components of the current instance using the specified escaping for special characters.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

获取 URI 的哈希代码。Gets the hash code for the URI.

GetLeftPart(UriPartial) GetLeftPart(UriPartial) GetLeftPart(UriPartial) GetLeftPart(UriPartial)

获取 Uri 实例的指定部分。Gets the specified portion of a Uri instance.

GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

返回序列化当前实例所需的数据。Returns the data needed to serialize the current instance.

GetType() GetType() GetType() GetType()

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

(Inherited from Object)
HexEscape(Char) HexEscape(Char) HexEscape(Char) HexEscape(Char)

将指定的字符转换为它的等效十六进制字符。Converts a specified character into its hexadecimal equivalent.

HexUnescape(String, Int32) HexUnescape(String, Int32) HexUnescape(String, Int32) HexUnescape(String, Int32)

将字符的指定十六进制表示形式转换为字符。Converts a specified hexadecimal representation of a character to the character.

InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
IsBadFileSystemCharacter(Char) IsBadFileSystemCharacter(Char) IsBadFileSystemCharacter(Char) IsBadFileSystemCharacter(Char)

获取一个值,该值指示字符是否在文件系统名称中无效。Gets whether a character is invalid in a file system name.

IsBaseOf(Uri) IsBaseOf(Uri) IsBaseOf(Uri) IsBaseOf(Uri)

确定当前的 Uri 实例是否为指定 Uri 实例的基。Determines whether the current Uri instance is a base of the specified Uri instance.

IsExcludedCharacter(Char) IsExcludedCharacter(Char) IsExcludedCharacter(Char) IsExcludedCharacter(Char)

获取一个值,该值指示是否应该转义指定的字符。Gets whether the specified character should be escaped.

IsHexDigit(Char) IsHexDigit(Char) IsHexDigit(Char) IsHexDigit(Char)

确定指定的字符是否为有效的十六进制数字。Determines whether a specified character is a valid hexadecimal digit.

IsHexEncoding(String, Int32) IsHexEncoding(String, Int32) IsHexEncoding(String, Int32) IsHexEncoding(String, Int32)

确定字符串中的一个字符是否为十六进制编码。Determines whether a character in a string is hexadecimal encoded.

IsReservedCharacter(Char) IsReservedCharacter(Char) IsReservedCharacter(Char) IsReservedCharacter(Char)

获取一个值,该值指示指定的字符是否为保留字符。Gets whether the specified character is a reserved character.

IsWellFormedOriginalString() IsWellFormedOriginalString() IsWellFormedOriginalString() IsWellFormedOriginalString()

指示用于构造此 Uri 的字符串是否格式良好,以及它是否不需要进一步转义。Indicates whether the string used to construct this Uri was well-formed and is not required to be further escaped.

IsWellFormedUriString(String, UriKind) IsWellFormedUriString(String, UriKind) IsWellFormedUriString(String, UriKind) IsWellFormedUriString(String, UriKind)

通过尝试用字符串构造一个 URI 来指示字符串是否为格式良好的,并确保字符串不需要进一步转义。Indicates whether the string is well-formed by attempting to construct a URI with the string and ensures that the string does not require further escaping.

MakeRelative(Uri) MakeRelative(Uri) MakeRelative(Uri) MakeRelative(Uri)

确定两个 Uri 实例之间的差异。Determines the difference between two Uri instances.

MakeRelativeUri(Uri) MakeRelativeUri(Uri) MakeRelativeUri(Uri) MakeRelativeUri(Uri)

确定两个 Uri 实例之间的差异。Determines the difference between two Uri instances.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Parse() Parse() Parse() Parse()

分析当前实例的 URI 以确保它包含有效 URI 所需的所有部分。Parses the URI of the current instance to ensure it contains all the parts required for a valid URI.

ToString() ToString() ToString() ToString()

获取指定的 Uri 实例的规范化字符串表示形式。Gets a canonical string representation for the specified Uri instance.

TryCreate(String, UriKind, Uri) TryCreate(String, UriKind, Uri) TryCreate(String, UriKind, Uri) TryCreate(String, UriKind, Uri)

使用指定的 Uri 实例和 String 创建一个新的 UriKindCreates a new Uri using the specified String instance and a UriKind.

TryCreate(Uri, String, Uri) TryCreate(Uri, String, Uri) TryCreate(Uri, String, Uri) TryCreate(Uri, String, Uri)

使用指定基和相对 Uri 实例创建一个新的 StringCreates a new Uri using the specified base and relative String instances.

TryCreate(Uri, Uri, Uri) TryCreate(Uri, Uri, Uri) TryCreate(Uri, Uri, Uri) TryCreate(Uri, Uri, Uri)

使用指定基和相对 Uri 实例创建一个新的 UriCreates a new Uri using the specified base and relative Uri instances.

Unescape(String) Unescape(String) Unescape(String) Unescape(String)

转换指定的字符串,方法是将任何转义序列替换为相应的未转义表示形式。Converts the specified string by replacing any escape sequences with their unescaped representation.

UnescapeDataString(String) UnescapeDataString(String) UnescapeDataString(String) UnescapeDataString(String)

将字符串转换为它的非转义表示形式。Converts a string to its unescaped representation.

操作员

Equality(Uri, Uri) Equality(Uri, Uri) Equality(Uri, Uri) Equality(Uri, Uri)

确定两个 Uri 实例是否具有相同的值。Determines whether two Uri instances have the same value.

Inequality(Uri, Uri) Inequality(Uri, Uri) Inequality(Uri, Uri) Inequality(Uri, Uri)

确定两个 Uri 实例是否具有不同的值。Determines whether two Uri instances do not have the same value.

显式界面实现

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

返回序列化当前实例所需的数据。Returns the data needed to serialize the current instance.

适用于

另请参阅