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 = 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 包含前置或尾端空格,則會保留這些空格。

這個屬性所傳回的值與 ToStringAbsoluteUri 不同。 ToString 會傳回 URI 的 Canonically unescaped 形式。 AbsoluteUri 會傳回 URI 的 Canonically 逸出形式。

當啟用國際資源識別碼 (IRI) 和國際化功能變數名稱 (IDN) 支援時,如果使用 Punycode 主機名稱來初始化 Uri 實例, OriginalString 則會傳回具有 Punycode 主機名稱的原始非正規化字串。 Punycode 名稱只包含 ASCII 字元,而且開頭一律為前置詞 xn--。

如需 IRI 支援的詳細資訊,請參閱 類別的 Uri 一節。

Uri序列化 物件時, OriginalString 不會保留 。 序列化程式會在序列化時使用完全逸出和正式的屬性 AbsoluteUriUri對於包含 IPv6 位址的 ,IPv6 位址和範圍識別碼會包含在序列化 Uri 物件中。

適用於