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
public ref class Uri : System::Runtime::Serialization::ISerializable
public ref class Uri : MarshalByRefObject, System::Runtime::Serialization::ISerializable
public class Uri
public class Uri : System.Runtime.Serialization.ISerializable
public class Uri : MarshalByRefObject, System.Runtime.Serialization.ISerializable
public class Uri : System.Runtime.Serialization.ISerializable
type Uri = class
type Uri = class
    interface ISerializable
type Uri = class
    inherit MarshalByRefObject
    interface ISerializable
Public Class Uri
Public Class Uri
Implements ISerializable
Public Class Uri
Inherits MarshalByRefObject
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 );
Dim siteUri As New Uri("http://www.contoso.com/")
Dim wr As WebRequest = WebRequest.Create(siteUri)


URI 是可供您的應用程式在內部網路或網際網路上使用之資源的精簡標記法。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. 若要將 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).

  • 藉由壓縮序列(例如/./、/.)來正常化階層式 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
var uri = new Uri("http://myUrl/%2E%2E/%2E%2E"); // http scheme, escaped
var uri = new Uri("ftp://myUrl/../.."); // ftp scheme, unescaped
var uri = new Uri("ftp://myUrl/%2E%2E/%2E%2E"); // ftp scheme, escaped


執行此程式碼時,它會傳回下列輸出,並在必要時將未加上轉義的序列換成,然後進行壓縮。When this code is executed, it returns the following output, with the escaped sequences unescaped if necessary and then compacted.


您可以使用 ToString 方法,將 Uri 類別的內容從轉義編碼的 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 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 的規格記載于由網際網路工程任務推動小組(IETF)發行的 RFC 2396、RFC 2732、RFC 3986 和 RFC 3987。The specifications for URIs are documented in RFC 2396, RFC 2732, RFC 3986, and RFC 3987 published by the Internet Engineering Task Force (IETF).

隨著網際網路的成長,識別使用非英文語言資源的需求也持續成長。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. 4.5 版之前的 .NET Framework 版本使用者不會看到任何來自 .NET Framework 2.0 行為的變更,除非它們特別啟用 IRI。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:

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

.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. 這是為了支援網際網路上現有的 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

    這個值會將不在近端內部網路上的所有 Unicode 功能變數名稱轉換成使用 Punycode 對等專案(IDN 名稱)。This value will convert all Unicode domain names not on the local Intranet to use the Punycode equivalents (IDN names). 在此情況下,若要處理近端內部網路上的國際名稱,用於內部網路的 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 剖析時(g enabled = 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 類別中的 IRI 和 IDN 處理也可以使用 System.Configuration.IriParsingElementSystem.Configuration.IdnElementSystem.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.Uri 類別時,System.Configuration.IriParsingElementSystem.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.GenericUriParser 物件行為的方法,是將 System.GenericUriParserOptions 列舉中的可用值位元組合傳遞至 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.

安全性考量Security Considerations

基於安全性考慮,在接受來自不受信任來源的 Uri 實例,以及在此函式中將 dontEscape設定為 true 時,您的應用程式應該特別小心。Because of security concerns, your application should use caution when accepting Uri instances from untrusted sources and with dontEscape set to true in the constructor. 您可以藉由呼叫 IsWellFormedOriginalString 方法,檢查 URI 字串的有效性。You can check a URI string for validity by calling the IsWellFormedOriginalString method.

當處理不受信任的使用者輸入時,請在信任其屬性之前,先確認新建立之 Uri 實例的相關假設。When dealing with untrusted user input, confirm assumptions about the newly created Uri instance before trusting its properties. 這可以透過下列方式來完成:This can be done in the following way:

string userInput = ...;

Uri baseUri = new Uri("https://myWebsite/files/");

if (!Uri.TryCreate(baseUri, userInput, out Uri newUri))
    // Fail: invalid input.

if (!baseUri.IsBaseOf(newUri))
    // Fail: the Uri base has been modified - the created Uri is not rooted in the original directory.

這項驗證可用於其他情況,例如處理 UNC 路徑時,只需變更 baseUriThis validation can be used in other cases, like when dealing with UNC paths, by simply changing the baseUri:

Uri baseUri = new Uri(@"\\host\share\some\directory\name\");

效能考量Performance Considerations

如果您使用包含 Uri 的 * Web.config * 檔案來初始化您的應用程式,則需要額外的時間來處理 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(SerializationInfo, StreamingContext)

初始化 Uri 類別的新執行個體,這個執行個體是來自 SerializationInfoStreamingContext 類別的指定執行個體。Initializes a new instance of the Uri class from the specified instances of the SerializationInfo and StreamingContext classes.


使用指定的 URI,初始化 Uri 類別的新執行個體。Initializes a new instance of the Uri class with the specified URI.

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,初始化 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 字串,初始化 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 類別的新執行個體。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 類別的新執行個體。Initializes a new instance of the Uri class based on the combination of a specified base Uri instance and a relative Uri instance.



指定會將通訊協定配置和 URI 的位址部分分隔開來的字元。Specifies the characters that separate the communication protocol scheme from the address portion of the URI. 此欄位為唯讀。This field is read-only.


指定 URI 為檔案的指標。Specifies that the URI is a pointer to a file. 此欄位為唯讀。This field is read-only.


指定 URI 要透過檔案傳輸通訊協定 (File Transfer Protocol,FTP) 存取。Specifies that the URI is accessed through the File Transfer Protocol (FTP). 此欄位為唯讀。This field is read-only.


指定 URI 要透過 Gopher 通訊協定存取。Specifies that the URI is accessed through the Gopher protocol. 此欄位為唯讀。This field is read-only.


指定 URI 要透過超文字傳輸協定 (Hypertext Transfer Protocol,HTTP) 存取。Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). 此欄位為唯讀。This field is read-only.


指定 URI 要透過安全超文字傳輸協定 (Secure Hypertext Transfer Protocol,HTTPS) 存取。Specifies that the URI is accessed through the Secure Hypertext Transfer Protocol (HTTPS). 此欄位為唯讀。This field is read-only.


指定 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.


指定 URI 會透過 Windows Communication Foundation (WCF) 所用的 NetPipe 配置來存取。Specifies that the URI is accessed through the NetPipe scheme used by Windows Communication Foundation (WCF). 此欄位為唯讀。This field is read-only.


指定 URI 會透過 Windows Communication Foundation (WCF) 所用的 NetTcp 配置來存取。Specifies that the URI is accessed through the NetTcp scheme used by Windows Communication Foundation (WCF). 此欄位為唯讀。This field is read-only.


指定 URI 為網際網路新聞群組,並且要透過 Network News Transport Protocol (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.


指定 URI 為網際網路新聞群組,並且要透過 Network News Transport Protocol (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.



取得 URI 的絕對路徑。Gets the absolute path of the URI.


取得絕對 URI。Gets the absolute URI.


取得伺服器的網域名稱系統 (DNS) 主機名稱或 IP 位址,以及連接埠編號。Gets the Domain Name System (DNS) host name or IP address and the port number for a server.


取得在視需要取消逸出後,可放心用於 DNS 解析的主機名稱。Gets a host name that, after being unescaped if necessary, is safe to use for DNS resolution.


取得逸出的 URI 片段。Gets the escaped URI fragment.


取得這個執行個體的主機元件。Gets the host component of this instance.


取得 URI 中所指定主機名稱的類型。Gets the type of the host name specified in the URI.


主機之符合 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.


取得 Uri 執行個體是否為絕對。Gets whether the Uri instance is absolute.


取得 URI 的通訊埠值是否為這個配置的預設值。Gets whether the port value of the URI is the default for this scheme.


取得表示指定的 Uri 是否為檔案 URI 的值。Gets a value indicating whether the specified Uri is a file URI.


取得指定的 Uri 是否參考本端主機。Gets whether the specified Uri references the local host.


取得指定的 Uri 是否為通用命名慣例 (Universal Naming Convention,UNC) 路徑。Gets whether the specified Uri is a universal naming convention (UNC) path.


取得檔案名稱的本機作業系統表示。Gets a local operating-system representation of a file name.


取得傳遞給 Uri 建構函式的原始 URI 字串。Gets the original URI string that was passed to the Uri constructor.


取得以問號 (?) 分隔的 AbsolutePathQuery 屬性。Gets the AbsolutePath and Query properties separated by a question mark (?).


取得這個 URI 的連接埠編號。Gets the port number of this URI.


取得指定的 URI 所包含的任何查詢資訊。Gets any query information included in the specified URI.


取得這個 URI 的配置名稱。Gets the scheme name for this URI.


取得陣列,包含構成指定 URI 的路徑區段。Gets an array containing the path segments that make up the specified URI.


表示 URI 字串在 Uri 執行個體建立之前即已完全逸出。Indicates that the URI string was completely escaped before the Uri instance was created.


取得與指定 URI 關聯的使用者名稱、密碼或其他使用者特定的資訊。Gets the user name, password, or other user-specific information associated with the specified URI.



將內部儲存的 URI 轉換成標準格式。Converts the internally stored URI to canonical form.


判斷指定的主機名稱是否為有效的 DNS 名稱。Determines whether the specified host name is a valid DNS name.


判斷指定的配置名稱是否有效。Determines whether the specified scheme name is valid.


呼叫這個方法沒有任何作用。Calling this method has no effect.

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

使用指定的比較規則,比較兩個 URI 的指定部分。Compares the specified parts of two URIs using the specified comparison rules.


建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)

比較兩個 Uri 執行個體是否相等。Compares two Uri instances for equality.


將路徑元件中的任何不安全或保留字元轉換成十六進位字元表示。Converts any unsafe or reserved characters in the path component to their hexadecimal character representations.


將字串轉換成它的逸出表示。Converts a string to its escaped representation.


將字串轉換成它的逸出表示。Converts a string to its escaped representation.


將 URI 字串轉換成它的逸出表示。Converts a URI string to its escaped representation.


取得十六進位數字的十進位值。Gets the decimal value of a hexadecimal digit.

GetComponents(UriComponents, UriFormat)

針對特殊字元使用指定的逸出方式,取得目前執行個體的指定元件。Gets the specified components of the current instance using the specified escaping for special characters.


取得 URI 的雜湊碼。Gets the hash code for the URI.


取得 Uri 執行個體的指定部分。Gets the specified portion of a Uri instance.


擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetObjectData(SerializationInfo, StreamingContext)

傳回序列化目前執行個體所需的資料。Returns the data needed to serialize the current instance.


取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)

將指定的字元轉換成其對等的十六進位數字。Converts a specified character into its hexadecimal equivalent.

HexUnescape(String, Int32)

將字元的指定十六進位表示轉換成字元。Converts a specified hexadecimal representation of a character to the character.


取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)

取得字元在檔案系統名稱中是否無效。Gets whether a character is invalid in a file system name.


判斷目前 Uri 執行個體是否為指定之 Uri 執行個體的基底。Determines whether the current Uri instance is a base of the specified Uri instance.


取得是否應該逸出指定的字元。Gets whether the specified character should be escaped.


判斷指定的字元是否為有效的十六進位數字。Determines whether a specified character is a valid hexadecimal digit.

IsHexEncoding(String, Int32)

判斷字串中的字元是否為十六進位編碼。Determines whether a character in a string is hexadecimal encoded.


取得指定的字元是否為保留字元。Gets whether the specified character is a reserved character.


表示用以建構此 Uri 之字串的語式是否正確,而且不需要進一步逸出。Indicates whether the string used to construct this Uri was well-formed and is not required to be further escaped.

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.


判斷兩個 Uri 執行個體之間的差別。Determines the difference between two Uri instances.


判斷兩個 Uri 執行個體之間的差別。Determines the difference between two Uri instances.


建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(Inherited from Object)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)

剖析目前執行個體的 URI,確定它包含有效 URI 所需的所有部分。Parses the URI of the current instance to ensure it contains all the parts required for a valid URI.


取得指定之 Uri 執行個體的標準字串表示。Gets a canonical string representation for the specified Uri instance.

TryCreate(String, UriKind, Uri)

使用指定的 Uri 執行個體和 String,建立新的 UriKindCreates a new Uri using the specified String instance and a UriKind.

TryCreate(Uri, String, Uri)

使用指定的基底和相對 Uri 執行個體,建立新的 StringCreates a new Uri using the specified base and relative String instances.

TryCreate(Uri, Uri, Uri)

使用指定的基底和相對 Uri 執行個體,建立新的 UriCreates a new Uri using the specified base and relative Uri instances.


轉換指定的字串,方法是將任何逸出序列取代成未逸出的表示。Converts the specified string by replacing any escape sequences with their unescaped representation.


將字串轉換成它的未逸出表示。Converts a string to its unescaped representation.


Equality(Uri, Uri)

判斷兩個 Uri 執行個體的值是否相同。Determines whether two Uri instances have the same value.

Inequality(Uri, Uri)

判斷兩個 Uri 執行個體的值是否不同。Determines whether two Uri instances do not have the same value.

Explicit Interface Implementations

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

傳回序列化目前執行個體所需的資料。Returns the data needed to serialize the current instance.

Applies to

See also