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 包含前导空格或尾随空格,则保留这些空格。

此属性返回的值不同于 ToStringAbsoluteUriToString 返回 URI 的可转义形式。 AbsoluteUri 返回 URI 的规范转义形式。

启用国际资源标识符 (IRI) 和国际化域名 (IDN) 支持时, OriginalString 如果已使用 Punycode 主机名来初始化 Uri 实例,则返回原始非规范化字符串和 Punycode 主机名。 Punycode 名称只包含 ASCII 字符,并且始终以 xn-- 前缀开头。

有关 IRI 支持的详细信息,请参阅 类的 Uri “备注”部分。

Uri序列化对象时,OriginalString不会保留 。 序列化过程在序列化时使用完全转义和规范化 AbsoluteUri 属性。 Uri对于包含 IPv6 地址的 ,IPv6 地址和范围 ID 包含在序列化Uri对象中。

适用于