Uri.OriginalString Uri.OriginalString Uri.OriginalString Uri.OriginalString Property

定义

获取传递给 Uri 构造函数的原始 URI 字符串。Gets the original URI string that was passed to the Uri constructor.

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

属性值

包含构造此实例时指定的同一 URI,则为 String;否则,为 EmptyA String containing the exact URI specified when this instance was constructed; otherwise, Empty.

示例

下面的示例从字符串创建Uri一个新的实例。The following example creates a new Uri instance from a string. 它阐释了从OriginalString返回的值 (返回传递到构造函数的字符串) 和对的ToString调用 (返回字符串的规范形式) 之间的差异。It illustrates the difference between the value returned from OriginalString, which returns the string that was passed to the constructor, and from a call to ToString, which returns the canonical form of the 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 orginal 
// 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 orginal 
// 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.
    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 orginal 
    ' 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 'SampleOriginalString

注解

如果为构造函数指定的 URI 包含前导空格或尾随空格, 则会保留这些空格。If the URI specified to the constructor contained leading or trailing spaces, these spaces are preserved.

此属性返回的值不同于ToString和。 AbsoluteUriThe value returned by this property differs from ToString and AbsoluteUri. ToString返回 URI 的规范非转义形式。ToString returns the canonically unescaped form of the URI. AbsoluteUri返回 URI 的规范转义形式。AbsoluteUri returns the canonically escaped form of the URI.

如果启用了国际资源标识符 (IRI) 和国际化域名 (IDN) 支持, OriginalString则将返回具有 Punycode 主机名的原始非规范化字符串 (如果使用了一个) 来初始化该Uri实例。When International Resource Identifier (IRI) and Internationalized Domain Name (IDN) support are enabled, OriginalString returns the original non normalized string with Punycode host name if one was used to initialize the Uri instance. Punycode 名称只包含 ASCII 字符,并且始终以 xn-- 前缀开头。Punycode names contain only ASCII characters and always start with the xn-- prefix.

有关 IRI 支持的详细信息, 请参阅Uri类的 "备注" 部分。For more information on IRI support, see the Remarks section for the Uri class.

序列化OriginalString对象时, 不会保留。 UriWhen a Uri object is serialized, the OriginalString is not preserved. 序列化时, 序列化过程使用完全AbsoluteUri转义和规范化属性。The serialization process uses the fully escaped and canonicalized AbsoluteUri property when serializing. 对于包含 ipv6 地址的, ipv6 地址和作用域 ID 包括在序列化Uri的对象中。 UriFor a Uri that contains an IPv6 address, the IPv6 address and the scope ID are included in the serialized Uri object.

适用于