Partager via


Uri.OriginalString Propriété

Définition

Obtient la chaîne d’URI d’origine qui a été passée au Uri constructeur.

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

Valeur de propriété

URI exact spécifié lors de la construction de cette instance ; sinon, Empty.

Exemples

L’exemple suivant crée une Uri instance à partir d’une chaîne. Il illustre la différence entre la valeur retournée par OriginalString, qui retourne la chaîne qui a été passée au constructeur, et d’un appel à ToString, qui retourne la forme canonique de la chaîne.

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

Remarques

Si l’URI spécifié au constructeur contenait des espaces de début ou de fin, ces espaces sont conservés.

La valeur retournée par cette propriété diffère de ToString et AbsoluteUri. ToString retourne la forme canonique non échappée de l’URI. AbsoluteUri retourne la forme d’échappement canonique de l’URI.

Lorsque la prise en charge de l’identificateur de ressource international (IRI) et du nom de domaine international (IDN) est activée, OriginalString retourne la chaîne non normalisée d’origine avec le nom d’hôte Punycode si l’un d’eux a été utilisé pour initialiser l’instance Uri . Les noms Punycode contiennent uniquement des caractères ASCII et commencent toujours par le préfixe xn- .

Pour plus d’informations sur la prise en charge de l’IRI, consultez la section Notes pour la Uri classe.

Lorsqu’un Uri objet est sérialisé, il OriginalString n’est pas conservé. Le processus de sérialisation utilise la propriété entièrement échapée et canonique AbsoluteUri lors de la sérialisation. Pour obtenir une Uri adresse IPv6, l’adresse IPv6 et l’ID d’étendue sont inclus dans l’objet sérialisé Uri .

S’applique à