Uri.OriginalString 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得傳遞給 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 = gcnew 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 );
// The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
Console::WriteLine( uriAddress->OriginalString );
// 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 包含前置或尾端空格,則會保留這些空格。
這個屬性所傳回的值與 ToString 和 AbsoluteUri 不同。 ToString 會傳回 URI 的 Canonically unescaped 形式。 AbsoluteUri 會傳回 URI 的 Canonically 逸出形式。
當啟用國際資源識別碼 (IRI) 和國際化功能變數名稱 (IDN) 支援時,如果使用 Punycode 主機名稱來初始化 Uri 實例, OriginalString 則會傳回具有 Punycode 主機名稱的原始非正規化字串。 Punycode 名稱只包含 ASCII 字元,而且開頭一律為前置詞 xn--。
如需 IRI 支援的詳細資訊,請參閱 類別的 Uri 一節。
Uri序列化 物件時, OriginalString 不會保留 。 序列化程式會在序列化時使用完全逸出和正式的屬性 AbsoluteUri 。 Uri對於包含 IPv6 位址的 ,IPv6 位址和範圍識別碼會包含在序列化 Uri 物件中。
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |