Uri.OriginalString Properti

Definisi

Mendapatkan string URI asli yang diteruskan ke Uri konstruktor.

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

Nilai Properti

URI yang tepat ditentukan ketika instans ini dibangun; jika tidak, Empty.

Contoh

Contoh berikut membuat instans baru Uri dari string. Ini mengilustrasikan perbedaan antara nilai yang dikembalikan dari OriginalString, yang mengembalikan string yang diteruskan ke konstruktor, dan dari panggilan ke ToString, yang mengembalikan bentuk kanonis string.

// 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

Keterangan

Jika URI yang ditentukan ke konstruktor berisi spasi di depan atau di belakang, spasi ini dipertahankan.

Nilai yang dikembalikan oleh properti ini berbeda dari ToString dan AbsoluteUri. ToString mengembalikan bentuk URI yang tidak dilepaskan secara kanonis. AbsoluteUri mengembalikan bentuk URI yang lolos secara kanonis.

Ketika dukungan International Resource Identifier (IRI) dan Internationalized Domain Name (IDN) diaktifkan, OriginalString mengembalikan string asli yang tidak dinormalisasi dengan nama host Punycode jika digunakan untuk menginisialisasi Uri instans. Nama punycode hanya berisi karakter ASCII dan selalu dimulai dengan awalan xn--.

Untuk informasi selengkapnya tentang dukungan IRI, lihat bagian Keterangan untuk Uri kelas .

Ketika objek diserialisasikan Uri , OriginalString tidak dipertahankan. Proses serialisasi menggunakan properti yang sepenuhnya lolos dan kanonis AbsoluteUri saat melakukan serialisasi. Uri Untuk yang berisi alamat IPv6, alamat IPv6 dan ID cakupan disertakan dalam objek berseriUri.

Berlaku untuk