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 进行扩展, 以使其为绝对 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. 为了以规范形式放置 URI, Uri构造函数执行以下步骤: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.

  • 默认情况下, URI 中的任何保留字符都根据 RFC 2396 进行转义。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 ToString使用方法, 将类的内容从转义编码的 uri 引用转换为可读的 uri 引用。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. 这是为了支持从返回ToString的值明确地重构 URI。This 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. 例如, URI xyz: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 协议的四位表示法中使用 IP 地址, 对 IPv6 协议支持使用冒号十六进制。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.

RFC 2396、RFC 2732、RFC 3986 和由 Internet 工程任务组 (IETF) 发布的 RFC 3987 中记录了 Uri 规范。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 v 3.5、3.0 SP1 和 2.0 SP1 中扩展了现有类, 以便基于 RFC 3987 提供 IRI 支持。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, 否则版本4.5 之前的 .NET Framework 版本的用户将看不到 .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. 不能使用 .config文件更改 IRI 分析。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.

根据所使用的 DNS 服务器, IDN 有三个可能的值:There are three possible values for IDN depending on the DNS servers that are used:

  • 已启用 idn = 全部idn enabled = All

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

  • 启用 idn = AllExceptIntranetidn enabled = AllExceptIntranet

    此值会将本地 Intranet 上的所有 Unicode 域名转换为使用 Punycode 等效项 (IDN 名称)。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). 在版本4.5 之前的 .NET Framework 版本中, 默认值为falseIn versions of the .NET Framework before version 4.5, the default value is false. 在 .NET Framework 版本4.5 及更高版本中, 默认true值为, 并且在 .config文件中, 不能修改启用了 IRI 分析功能的状态。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.

Uri还可以System.Configuration.IriParsingElement使用、 System.Configuration.IdnElement和配置设置类控制类中的IRI和IDN处理。System.Configuration.UriSectionIRI 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.IriParsingElement System.Uri类时System.Configuration.IdnElement , 和的配置设置将被读取一次。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。可以通过调用IsWellFormedOriginalString()方法来检查 URI 字符串的有效性。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.

适用于

另请参阅