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,而此属性仅对绝对 URI 有效。This instance represents a relative URI, and this property is valid only for absolute URIs.

示例

下面的示例创建一个新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.

此属性返回的值与不同ToStringAbsoluteUriThe 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.

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

适用于