Uri.OriginalString Właściwość

Definicja

Pobiera oryginalny ciąg identyfikatora URI, który został przekazany do konstruktora Uri .

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

Wartość właściwości

Dokładny identyfikator URI określony podczas konstruowania tego wystąpienia; w przeciwnym razie , Empty.

Przykłady

Poniższy przykład tworzy nowe Uri wystąpienie na podstawie ciągu. Ilustruje to różnicę między wartością zwróconą z OriginalStringklasy , która zwraca ciąg przekazany do konstruktora i z wywołania metody , która zwraca postać ToStringkanoniczną ciągu.

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

Uwagi

Jeśli identyfikator URI określony dla konstruktora zawiera spacje wiodące lub końcowe, te spacje są zachowywane.

Wartość zwracana przez tę właściwość różni się od ToString wartości i AbsoluteUri. ToString metoda zwraca kanonicznie niewysobioną formę identyfikatora URI. AbsoluteUri Metoda zwraca kanonicznie unikniętą postać identyfikatora URI.

Gdy włączono obsługę międzynarodowego identyfikatora zasobów (IRI) i międzynarodowej nazwy domeny (IDN), zwraca oryginalny nieznormalizowany ciąg z nazwą hosta Punycode, OriginalString jeśli użyto go do zainicjowania Uri wystąpienia. Nazwy punycode zawierają tylko znaki ASCII i zawsze zaczynają się od prefiksu xn-- .

Aby uzyskać więcej informacji na temat obsługi IRI, zobacz sekcję Uri Uwagi dla klasy.

Uri Gdy obiekt jest serializowany, OriginalString obiekt nie jest zachowywany. Proces serializacji używa w pełni ucieczki i kanonicznej AbsoluteUri właściwości podczas serializacji. W przypadku obiektu Uri zawierającego adres IPv6 adres IPv6 i identyfikator zakresu są uwzględniane w serializowanym Uri obiekcie.

Dotyczy