共用方式為


Uri.OriginalString 屬性

定義

取得傳給 Uri 建構子的原始 URI 字串。

public:
 property System::String ^ OriginalString { System::String ^ get(); };
public string OriginalString { get; }
member this.OriginalString : string
Public ReadOnly Property OriginalString As String

屬性值

精確的 URI 會指定此實例建構的時間;否則,。 Empty

範例

以下範例是從字串建立一個新 Uri 實例。 它說明了從 OriginalString返回的值(回傳給建構子的字串)與從呼叫 返回 ToString字串的典範形式的差異。

// Create a new Uri from a string address.
Uri uriAddress = new Uri("HTTP://www.ConToso.com:80//thick%20and%20thin.htm");

// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version. OriginalString gives the original
// string that was passed to the constructor.

// The following outputs "http://www.contoso.com//thick and thin.htm".
Console.WriteLine(uriAddress.ToString());

// The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
Console.WriteLine(uriAddress.OriginalString);
// Create a new Uri from a string address.
let uriAddress = Uri "HTTP://www.ConToso.com:80//thick%20and%20thin.htm"

// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version. OriginalString gives the original
// string that was passed to the constructor.

// The following outputs "http://www.contoso.com//thick and thin.htm".
printfn $"{uriAddress.ToString()}"

// The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
printfn $"{uriAddress.OriginalString}"
    ' Create a new Uri from a string address.
    Dim uriAddress As New Uri("HTTP://www.ConToso.com:80//thick%20and%20thin.htm")
    
    ' Write the new Uri to the console and note the difference in the two values.
    ' ToString() gives the canonical version. OriginalString gives the original 
    ' string that was passed to the constructor.
    ' The following outputs "http://www.contoso.com//thick and thin.htm".
    Console.WriteLine(uriAddress.ToString())
    
    ' The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
    Console.WriteLine(uriAddress.OriginalString)

End Sub

備註

若建構子指定的 URI 包含前置或後置空間,這些空格會被保留。

此性質返回的值與 ToStringAbsoluteUri不同。 ToString 回歸官方未逃脫的URI形式。 AbsoluteUri 返回官方逃離的URI形式。

當啟用國際資源識別碼(IRI)及國際化網域名稱(IDN)支援時, OriginalString 若使用 Punycode 主機名稱初始 Uri 化,則會回傳原始未正規化字串及 Punycode 主機名稱。 Punycode 名稱只包含 ASCII 字元,且一律以 xn-- 前置詞開頭。

欲了解更多關於IRI支援的資訊,請參閱該 Uri 課程備註區。

當物件 Uri 被序列化時,不會 OriginalString 被保留。 序列化過程在序列化時會使用完全轉義與標準化 AbsoluteUri 的特性。 對於包含 IPv6 位址的 a Uri ,則 IPv6 位址與作用域 ID 會包含在序列化 Uri 物件中。

適用於