次の方法で共有


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 = 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 の正規のエスケープされていない形式を返します。 AbsoluteUri は、URI の正規エスケープ形式を返します。

International Resource Identifier (IRI) と Internationalized Domain Name (IDN) のサポートが有効になっている場合、 OriginalString は、 Uri インスタンスの初期化に使用された場合、Punycode ホスト名を持つ元の正規化されていない文字列を返します。 Punycode 名には ASCII 文字のみが含まれ、常に xn-- プレフィックスで始まります。

IRI サポートの詳細については、 Uri クラスの「解説」セクションを参照してください。

Uri オブジェクトをシリアル化すると、OriginalStringは保持されません。 シリアル化プロセスでは、シリアル化時に完全にエスケープされた正規化された AbsoluteUri プロパティが使用されます。 IPv6 アドレスを含む Uri の場合、シリアル化された Uri オブジェクトには IPv6 アドレスとスコープ ID が含まれます。

適用対象