Uri Uri Uri Uri Constructors

定义

重载

Uri(String) Uri(String) Uri(String) Uri(String)

用指定的 URI 初始化 Uri 类的新实例。Initializes a new instance of the Uri class with the specified URI.

Uri(SerializationInfo, StreamingContext) Uri(SerializationInfo, StreamingContext) Uri(SerializationInfo, StreamingContext)

UriSerializationInfo 类的指定实例初始化 StreamingContext 类的新实例。Initializes a new instance of the Uri class from the specified instances of the SerializationInfo and StreamingContext classes.

Uri(String, Boolean) Uri(String, Boolean) Uri(String, Boolean) Uri(String, Boolean)

用指定的 URI 初始化 Uri 类的新实例,并对字符转义进行显式控制。Initializes a new instance of the Uri class with the specified URI, with explicit control of character escaping.

Uri(String, UriKind) Uri(String, UriKind) Uri(String, UriKind)

用指定的 URI 初始化 Uri 类的新实例。Initializes a new instance of the Uri class with the specified URI. 此构造函数允许指定 URI 字符串是相对 URI、绝对 URI 还是不确定。This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate.

Uri(Uri, String) Uri(Uri, String) Uri(Uri, String) Uri(Uri, String)

根据指定的基 URI 和相对 URI 字符串,初始化 Uri 类的新实例。Initializes a new instance of the Uri class based on the specified base URI and relative URI string.

Uri(Uri, Uri) Uri(Uri, Uri) Uri(Uri, Uri) Uri(Uri, Uri)

根据指定的基 Uri 实例和相对 Uri 实例的组合,初始化 Uri 类的新实例。Initializes a new instance of the Uri class based on the combination of a specified base Uri instance and a relative Uri instance.

Uri(Uri, String, Boolean) Uri(Uri, String, Boolean) Uri(Uri, String, Boolean) Uri(Uri, String, Boolean)

根据指定的基 URI 和相对 URI,初始化 Uri 类的新实例,并对字符转义进行显式控制。Initializes a new instance of the Uri class based on the specified base and relative URIs, with explicit control of character escaping.

Uri(String) Uri(String) Uri(String) Uri(String)

用指定的 URI 初始化 Uri 类的新实例。Initializes a new instance of the Uri class with the specified URI.

public:
 Uri(System::String ^ uriString);
public Uri (string uriString);
new Uri : string -> Uri
Public Sub New (uriString As String)

参数

uriString
String String String String

标识将由 Uri 实例表示的资源的字符串。A string that identifies the resource to be represented by the Uri instance. 请注意,必须用括号将字符串形式的 IPv6 地址括起来。Note that an IPv6 address in string form must be enclosed within brackets. 例如,“http://[2607:f8b0:400d:c06::69]”。For example, "http://[2607:f8b0:400d:c06::69]".

异常

适用于 Windows 应用商店应用的 .NET可移植类库中,改为捕获基类异常 FormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

uriString 为空。 uriString is empty.

- 或 --or- uriString 中指定的方案格式不正确。The scheme specified in uriString is not correctly formed. 请参阅 CheckSchemeName(String)See CheckSchemeName(String).

- 或 --or- uriString 包含过多斜杠。uriString contains too many slashes.

- 或 --or- uriString 中指定的密码无效。The password specified in uriString is not valid.

- 或 --or- uriString 中指定的主机名无效。The host name specified in uriString is not valid.

- 或 --or- uriString 中指定的文件名无效。The file name specified in uriString is not valid.

- 或 --or- uriString 中指定的用户名无效。The user name specified in uriString is not valid.

- 或 --or- uriString 中指定的主机名或证书颁发机构名称不能以反斜杠结尾。The host or authority name specified in uriString cannot be terminated by backslashes.

- 或 --or- uriString 中指定的端口号无效或无法分析。The port number specified in uriString is not valid or cannot be parsed.

- 或 --or- uriString 的长度超过 65519 个字符。The length of uriString exceeds 65519 characters.

- 或 --or- uriString 中指定的方案的长度超过 1023 个字符。The length of the scheme specified in uriString exceeds 1023 characters.

- 或 --or- uriString 中存在无效的字符序列。There is an invalid character sequence in uriString.

- 或 --or- uriString 中指定的 MS-DOS 路径必须以 c:\\ 开头。The MS-DOS path specified in uriString must start with c:\\.

示例

下面的示例创建Uri实例的 uri"http://www.contoso.com/"。The following example creates a Uri instance with the URI "http://www.contoso.com/".

Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
Uri myUri = new Uri("http://www.contoso.com/");

Dim myUri As New Uri("http://www.contoso.com/")

注解

此构造函数创建Uri从 URI 字符串的实例。This constructor creates a Uri instance from a URI string. 它分析 URI,将其放入规范格式,并使任何所需的转义编码。It parses the URI, puts it in canonical format, and makes any required escape encodings.

此构造函数不能确保Uri指的是可访问的资源。This constructor does not ensure that the Uri refers to an accessible resource.

此构造函数将假定string参数引用的绝对 URI,它是等效于调用Uri构造函数与UriKind设置为AbsoluteThis constructor assumes that the string parameter references an absolute URI and is equivalent to calling the Uri constructor with UriKind set to Absolute. 如果string传递给构造函数的参数是一个相对 URI,此构造函数将引发UriFormatExceptionIf the string parameter passed to the constructor is a relative URI, this constructor will throw a UriFormatException.

Uri(SerializationInfo, StreamingContext) Uri(SerializationInfo, StreamingContext) Uri(SerializationInfo, StreamingContext)

UriSerializationInfo 类的指定实例初始化 StreamingContext 类的新实例。Initializes a new instance of the Uri class from the specified instances of the SerializationInfo and StreamingContext classes.

protected:
 Uri(System::Runtime::Serialization::SerializationInfo ^ serializationInfo, System::Runtime::Serialization::StreamingContext streamingContext);
protected Uri (System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
new Uri : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> Uri

参数

serializationInfo
SerializationInfo SerializationInfo SerializationInfo SerializationInfo

SerializationInfo 类的实例,包含序列化新的 Uri 实例所需的信息。An instance of the SerializationInfo class containing the information required to serialize the new Uri instance.

streamingContext
StreamingContext StreamingContext StreamingContext StreamingContext

StreamingContext 类的实例,包含与新的 Uri 实例关联的序列化流的源。An instance of the StreamingContext class containing the source of the serialized stream associated with the new Uri instance.

异常

serializationInfo 参数包含 null URI。The serializationInfo parameter contains a null URI.

serializationInfo 参数包含一个为空的 URI。The serializationInfo parameter contains a URI that is empty.

- 或 --or- 指定的方案形式不正确。The scheme specified is not correctly formed. 请参阅 CheckSchemeName(String)See CheckSchemeName(String).

- 或 --or- 该 URI 包含过多斜杠。The URI contains too many slashes.

- 或 --or- URI 中指定的密码无效。The password specified in the URI is not valid.

- 或 --or- URI 中指定的主机名无效。The host name specified in URI is not valid.

- 或 --or- URI 中指定的文件名无效。The file name specified in the URI is not valid.

- 或 --or- URI 中指定的用户名无效。The user name specified in the URI is not valid.

- 或 --or- URI 中指定的主机名或证书颁发机构名称不能以反斜杠结尾。The host or authority name specified in the URI cannot be terminated by backslashes.

- 或 --or- URI 中指定的端口号无效或无法分析。The port number specified in the URI is not valid or cannot be parsed.

- 或 --or- URI 的长度超过 65519 个字符。The length of URI exceeds 65519 characters.

- 或 --or- URI 中指定的方案的长度超过 1023 个字符。The length of the scheme specified in the URI exceeds 1023 characters.

- 或 --or- URI 中存在无效的字符序列。There is an invalid character sequence in the URI.

- 或 --or- URI 中指定的 MS-DOS 路径必须以 c:\\ 开头。The MS-DOS path specified in the URI must start with c:\\.

注解

此构造函数实现ISerializable接口Uri类。This constructor implements the ISerializable interface for the Uri class.

另请参阅

Uri(String, Boolean) Uri(String, Boolean) Uri(String, Boolean) Uri(String, Boolean)

警告

此 API 现已过时。

用指定的 URI 初始化 Uri 类的新实例,并对字符转义进行显式控制。Initializes a new instance of the Uri class with the specified URI, with explicit control of character escaping.

public:
 Uri(System::String ^ uriString, bool dontEscape);
[System.Obsolete("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")]
[System.Obsolete("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. https://go.microsoft.com/fwlink/?linkid=14202")]
public Uri (string uriString, bool dontEscape);
new Uri : string * bool -> Uri
Public Sub New (uriString As String, dontEscape As Boolean)

参数

uriString
String String String String

标识将由 Uri 实例表示的资源的字符串。A string that identifies the resource to be represented by the Uri instance. 请注意,必须用括号将字符串形式的 IPv6 地址括起来。Note that an IPv6 address in string form must be enclosed within brackets. 例如,“http://[2607:f8b0:400d:c06::69]”。For example, "http://[2607:f8b0:400d:c06::69]".

dontEscape
Boolean Boolean Boolean Boolean

如果 uriString 已完全转义,则为 true;否则为 falsetrue if uriString is completely escaped; otherwise, false.

异常

uriString 为空或只包含空格。uriString is empty or contains only spaces.

- 或 --or- uriString 中指定的方案无效。The scheme specified in uriString is not valid.

- 或 --or- uriString 包含过多斜杠。uriString contains too many slashes.

- 或 --or- uriString 中指定的密码无效。The password specified in uriString is not valid.

- 或 --or- uriString 中指定的主机名无效。The host name specified in uriString is not valid.

- 或 --or- uriString 中指定的文件名无效。The file name specified in uriString is not valid.

- 或 --or- uriString 中指定的用户名无效。The user name specified in uriString is not valid.

- 或 --or- uriString 中指定的主机名或证书颁发机构名称不能以反斜杠结尾。The host or authority name specified in uriString cannot be terminated by backslashes.

- 或 --or- uriString 中指定的端口号无效或无法分析。The port number specified in uriString is not valid or cannot be parsed.

- 或 --or- uriString 的长度超过 65519 个字符。The length of uriString exceeds 65519 characters.

- 或 --or- uriString 中指定的方案的长度超过 1023 个字符。The length of the scheme specified in uriString exceeds 1023 characters.

- 或 --or- uriString 中存在无效的字符序列。There is an invalid character sequence in uriString.

- 或 --or- uriString 中指定的 MS-DOS 路径必须以 c:\\ 开头。The MS-DOS path specified in uriString must start with c:\\.

示例

下面的示例创建Uriuri 实例http://www.contoso.com/Hello%20World.htm。The following example creates a Uri instance for the URI http://www.contoso.com/Hello%20World.htm. 因为包含的 URI 完全转义,而是采用规范格式dontEscape参数可以设置为trueBecause the contained URI is completely escaped and is in canonical form, the dontEscape parameter can be set to true.

Uri^ myUri = gcnew Uri(  "http://www.contoso.com/Hello%20World.htm",true );
Uri myUri = new Uri("http://www.contoso.com/Hello%20World.htm", true);

Dim myUri As New Uri("http://www.contoso.com/Hello%20World.htm", True)

注解

此构造函数创建Uri从 URI 字符串的实例。This constructor creates a Uri instance from a URI string. 它分析 URI,并将其放入规范格式。It parses the URI and puts it in canonical format.

dontEscape参数控制是否保留的字符将转换为转义序列。The dontEscape parameter controls whether reserved characters are translated into escape sequences. 此参数应设置为true仅当确定已转义的 URI 中的所有保留的字符。This parameter should be set to true only if you are certain that all reserved characters in the URI have been escaped. 将值设置为true为完全未转义的 URI 会导致意外的行为。Setting the value to true for a URI that has not been completely escaped can cause unexpected behavior. 强烈建议始终将此参数设置为falseIt is strongly recommended that you always set this parameter to false.

如果dontEscape设置为false,构造函数通过检查的转义任何保留的字符百分比 (%) 的所有匹配项后跟一个有效的转义序列。If dontEscape is set to false, the constructor escapes any reserved characters by checking that all occurrences of percent (%) are followed by a valid escape sequence. 如果百分号后面的字符序列不是有效的百分比是替换为 25%。If the character sequence following a percent is not valid, the percent is replaced by %25.

此构造函数不能确保Uri指的是可访问的资源。This constructor does not ensure that the Uri refers to an accessible resource.

Uri(String, UriKind) Uri(String, UriKind) Uri(String, UriKind)

用指定的 URI 初始化 Uri 类的新实例。Initializes a new instance of the Uri class with the specified URI. 此构造函数允许指定 URI 字符串是相对 URI、绝对 URI 还是不确定。This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate.

public:
 Uri(System::String ^ uriString, UriKind uriKind);
public Uri (string uriString, UriKind uriKind);
new Uri : string * UriKind -> Uri

参数

uriString
String String String String

标识将由 Uri 实例表示的资源的字符串。A string that identifies the resource to be represented by the Uri instance. 请注意,必须用括号将字符串形式的 IPv6 地址括起来。Note that an IPv6 address in string form must be enclosed within brackets. 例如,“http://[2607:f8b0:400d:c06::69]”。For example, "http://[2607:f8b0:400d:c06::69]".

uriKind
UriKind UriKind UriKind UriKind

指定 URI 字符串是相对 URI、绝对 URI 还是不确定。Specifies whether the URI string is a relative URI, absolute URI, or is indeterminate.

异常

适用于 Windows 应用商店应用的 .NET可移植类库中,改为捕获基类异常 FormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

uriString 包含相对 URI,而 uriKindAbsolute uriString contains a relative URI and uriKind is Absolute.

oror uriString 包含绝对 URI,而 uriKindRelativeuriString contains an absolute URI and uriKind is Relative.

oror uriString 为空。uriString is empty.

- 或 --or- uriString 中指定的方案格式不正确。The scheme specified in uriString is not correctly formed. 请参阅 CheckSchemeName(String)See CheckSchemeName(String).

- 或 --or- uriString 包含过多斜杠。uriString contains too many slashes.

- 或 --or- uriString 中指定的密码无效。The password specified in uriString is not valid.

- 或 --or- uriString 中指定的主机名无效。The host name specified in uriString is not valid.

- 或 --or- uriString 中指定的文件名无效。The file name specified in uriString is not valid.

- 或 --or- uriString 中指定的用户名无效。The user name specified in uriString is not valid.

- 或 --or- uriString 中指定的主机名或证书颁发机构名称不能以反斜杠结尾。The host or authority name specified in uriString cannot be terminated by backslashes.

- 或 --or- uriString 中指定的端口号无效或无法分析。The port number specified in uriString is not valid or cannot be parsed.

- 或 --or- uriString 的长度超过 65519 个字符。The length of uriString exceeds 65519 characters.

- 或 --or- uriString 中指定的方案的长度超过 1023 个字符。The length of the scheme specified in uriString exceeds 1023 characters.

- 或 --or- uriString 中存在无效的字符序列。There is an invalid character sequence in uriString.

- 或 --or- uriString 中指定的 MS-DOS 路径必须以 c:\\ 开头。The MS-DOS path specified in uriString must start with c:\\.

注解

相对和绝对 Uri 具有不同限制它们的格式。Relative and absolute URIs have different restrictions on their format. 例如,一个相对 URI 不需要的方案或证书颁发机构。For example, a relative URI does not require a scheme or an authority. 在指定的值uriKind中传递的 URI 的类型必须匹配uriStringThe value you specify in uriKind must match the type of URI passed in uriString. 但是,如果RelativeOrAbsoluteURI 字符串可以相对或绝对的指定。However, if RelativeOrAbsolute is specified, the URI string can be relative or absolute.

Uri(Uri, String) Uri(Uri, String) Uri(Uri, String) Uri(Uri, String)

根据指定的基 URI 和相对 URI 字符串,初始化 Uri 类的新实例。Initializes a new instance of the Uri class based on the specified base URI and relative URI string.

public:
 Uri(Uri ^ baseUri, System::String ^ relativeUri);
public Uri (Uri baseUri, string relativeUri);
new Uri : Uri * string -> Uri
Public Sub New (baseUri As Uri, relativeUri As String)

参数

baseUri
Uri Uri Uri Uri

基 URI。The base URI.

relativeUri
String String String String

要添加到基 URI 的相对 URI。The relative URI to add to the base URI.

异常

baseUri 不是绝对的 Uri 实例。baseUri is not an absolute Uri instance.

适用于 Windows 应用商店应用的 .NET可移植类库中,改为捕获基类异常 FormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

通过组合 baseUrirelativeUri 而构成的 URI 为空或仅包含空格。The URI formed by combining baseUri and relativeUri is empty or contains only spaces.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的方案无效。The scheme specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 包含过多的斜杠。The URI formed by combining baseUri and relativeUri contains too many slashes.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的密码无效。The password specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的主机名无效。The host name specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的文件名无效。The file name specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的用户名无效。The user name specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的主机名或证书颁发机构名称不能以反斜杠终止。The host or authority name specified in the URI formed by combining baseUri and relativeUri cannot be terminated by backslashes.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的端口号无效或无法分析。The port number specified in the URI formed by combining baseUri and relativeUri is not valid or cannot be parsed.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 的长度超过 65519 个字符。The length of the URI formed by combining baseUri and relativeUri exceeds 65519 characters.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的方案长度超过 1023 个字符。The length of the scheme specified in the URI formed by combining baseUri and relativeUri exceeds 1023 characters.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中存在无效字符序列。There is an invalid character sequence in the URI formed by combining baseUri and relativeUri.

- 或 --or- uriString 中指定的 MS-DOS 路径必须以 c:\\ 开头。The MS-DOS path specified in uriString must start with c:\\.

示例

下面的示例创建的新实例Uri类的组合的相对 Uri http://www.contoso.com catalog/shownew.htm 以构成绝对 URI 和http://www.contoso.com/catalog/shownew.htm。The following example creates a new instance of the Uri class by combining the relative URIs http://www.contoso.com and catalog/shownew.htm to form the absolute URI http://www.contoso.com/catalog/shownew.htm.

Uri^ baseUri = gcnew Uri(  "http://www.contoso.com" );
Uri^ myUri = gcnew Uri( baseUri, "catalog/shownew.htm" );
Console::WriteLine( myUri->ToString() );
Uri baseUri = new Uri("http://www.contoso.com");
 Uri myUri = new Uri(baseUri, "catalog/shownew.htm");

Console.WriteLine(myUri.ToString());
   
Dim baseUri As New Uri("http://www.contoso.com")
Dim myUri As New Uri(baseUri, "catalog/shownew.htm")

Console.WriteLine(myUri.ToString())

注解

此构造函数创建Uri通过组合实例baseUrirelativeUriThis constructor creates a Uri instance by combining the baseUri and the relativeUri. 如果relativeUri是绝对的 URI (包含一种方案、 主机名和 (可选) 端口号),Uri实例创建仅使用relativeUriIf relativeUri is an absolute URI (containing a scheme, host name, and optionally a port number), the Uri instance is created using only relativeUri.

如果baseUri具有相对部分 (如/api),则必须以斜杠,终止的相对部分 (如/api/),如果的相对部分baseUri将被保留在构造UriIf the baseUri has relative parts (like /api), then the relative part must be terminated with a slash, (like /api/), if the relative part of baseUri is to be preserved in the constructed Uri.

此外,如果relativeUri以斜线,开头,则它将替换任何相对一部分 baseUriAdditionally, if the relativeUri begins with a slash, then it will replace any relative part of the baseUri

此构造函数不能确保Uri指的是可访问的资源。This constructor does not ensure that the Uri refers to an accessible resource.

Uri(Uri, Uri) Uri(Uri, Uri) Uri(Uri, Uri) Uri(Uri, Uri)

根据指定的基 Uri 实例和相对 Uri 实例的组合,初始化 Uri 类的新实例。Initializes a new instance of the Uri class based on the combination of a specified base Uri instance and a relative Uri instance.

public:
 Uri(Uri ^ baseUri, Uri ^ relativeUri);
public Uri (Uri baseUri, Uri relativeUri);
new Uri : Uri * Uri -> Uri
Public Sub New (baseUri As Uri, relativeUri As Uri)

参数

baseUri
Uri Uri Uri Uri

作为新 Uri 实例的基的绝对 UriAn absolute Uri that is the base for the new Uri instance.

relativeUri
Uri Uri Uri Uri

Uri 组合的相对 baseUri 实例。A relative Uri instance that is combined with baseUri.

异常

baseUri 不是绝对的 Uri 实例。baseUri is not an absolute Uri instance.

baseUri 不是绝对的 Uri 实例。baseUri is not an absolute Uri instance.

适用于 Windows 应用商店应用的 .NET可移植类库中,改为捕获基类异常 FormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

通过组合 baseUrirelativeUri 而构成的 URI 为空或仅包含空格。The URI formed by combining baseUri and relativeUri is empty or contains only spaces.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的方案无效。The scheme specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 包含过多的斜杠。The URI formed by combining baseUri and relativeUri contains too many slashes.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的密码无效。The password specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的主机名无效。The host name specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的文件名无效。The file name specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的用户名无效。The user name specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的主机名或证书颁发机构名称不能以反斜杠终止。The host or authority name specified in the URI formed by combining baseUri and relativeUri cannot be terminated by backslashes.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的端口号无效或无法分析。The port number specified in the URI formed by combining baseUri and relativeUri is not valid or cannot be parsed.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 的长度超过 65519 个字符。The length of the URI formed by combining baseUri and relativeUri exceeds 65519 characters.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的方案长度超过 1023 个字符。The length of the scheme specified in the URI formed by combining baseUri and relativeUri exceeds 1023 characters.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中存在无效字符序列。There is an invalid character sequence in the URI formed by combining baseUri and relativeUri.

- 或 --or- uriString 中指定的 MS-DOS 路径必须以 c:\\ 开头。The MS-DOS path specified in uriString must start with c:\\.

示例

此示例创建一个绝对Uri实例, absoluteUri,且是相对Uri实例, relativeUriThis example creates an absolute Uri instance, absoluteUri, and a relative Uri instance, relativeUri. 一个新Uri实例, combinedUri,然后创建从这两个实例。A new Uri instance, combinedUri, is then created from these two instances.

// Create an absolute Uri from a string.
String^ addressString1 = "http://www.contoso.com/";
String^ addressString2 = "catalog/shownew.htm?date=today";
Uri^ absoluteUri = gcnew Uri(addressString1);

// Create a relative Uri from a string.  allowRelative = true to allow for 
// creating a relative Uri.
Uri^ relativeUri = gcnew Uri(addressString2);

// Check whether the new Uri is absolute or relative.
if (  !relativeUri->IsAbsoluteUri )
   Console::WriteLine( "{0} is a relative Uri.", relativeUri );

// Create a new Uri from an absolute Uri and a relative Uri.
Uri^ combinedUri = gcnew Uri( absoluteUri,relativeUri );
Console::WriteLine( combinedUri->AbsoluteUri );
// Create an absolute Uri from a string.
Uri absoluteUri = new Uri("http://www.contoso.com/");

// Create a relative Uri from a string.  allowRelative = true to allow for 
// creating a relative Uri.
Uri relativeUri = new Uri("/catalog/shownew.htm?date=today", UriKind.Relative);

// Check whether the new Uri is absolute or relative.
if (!relativeUri.IsAbsoluteUri)
    Console.WriteLine("{0} is a relative Uri.", relativeUri);

// Create a new Uri from an absolute Uri and a relative Uri.
Uri combinedUri = new Uri(absoluteUri, relativeUri);
Console.WriteLine(combinedUri.AbsoluteUri);
    ' Create an absolute Uri from a string.
    Dim absoluteUri As New Uri("http://www.contoso.com/")
    
    ' Create a relative Uri from a string.  allowRelative = true to allow for 
    ' creating a relative Uri.
    Dim relativeUri As New Uri("/catalog/shownew.htm?date=today")
    
    ' Check whether the new Uri is absolute or relative.
    If Not relativeUri.IsAbsoluteUri Then
        Console.WriteLine("{0} is a relative Uri.", relativeUri)
    End If 
    ' Create a new Uri from an absolute Uri and a relative Uri.
    Dim combinedUri As New Uri(absoluteUri, relativeUri)
    Console.WriteLine(combinedUri.AbsoluteUri)

End Sub 'SampleConstructor

注解

此构造函数创建一个新Uri实例通过组合绝对Uri实例, baseUri,使用相对Uri实例, relativeUriThis constructor creates a new Uri instance by combining an absolute Uri instance, baseUri, with a relative Uri instance, relativeUri. 如果relativeUri是绝对Uri(包含一种方案、 主机名和 (可选) 端口号) 的实例,Uri仅使用创建实例relativeUriIf relativeUri is an absolute Uri instance (containing a scheme, host name, and optionally a port number), the Uri instance is created using only relativeUri.

如果baseUri具有相对部分 (如/api),则必须以斜杠,终止的相对部分 (如/api/),如果的相对部分baseUri将被保留在构造UriIf the baseUri has relative parts (like /api), then the relative part must be terminated with a slash, (like /api/), if the relative part of baseUri is to be preserved in the constructed Uri.

此外,如果relativeUri以斜线,开头,则它将替换任何相对一部分 baseUriAdditionally, if the relativeUri begins with a slash, then it will replace any relative part of the baseUri

此构造函数不能确保Uri指的是可访问的资源。This constructor does not ensure that the Uri refers to an accessible resource.

Uri(Uri, String, Boolean) Uri(Uri, String, Boolean) Uri(Uri, String, Boolean) Uri(Uri, String, Boolean)

警告

此 API 现已过时。

根据指定的基 URI 和相对 URI,初始化 Uri 类的新实例,并对字符转义进行显式控制。Initializes a new instance of the Uri class based on the specified base and relative URIs, with explicit control of character escaping.

public:
 Uri(Uri ^ baseUri, System::String ^ relativeUri, bool dontEscape);
[System.Obsolete("The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")]
[System.Obsolete("The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. https://go.microsoft.com/fwlink/?linkid=14202")]
public Uri (Uri baseUri, string relativeUri, bool dontEscape);
new Uri : Uri * string * bool -> Uri
Public Sub New (baseUri As Uri, relativeUri As String, dontEscape As Boolean)

参数

baseUri
Uri Uri Uri Uri

基 URI。The base URI.

relativeUri
String String String String

要添加到基 URI 的相对 URI。The relative URI to add to the base URI.

dontEscape
Boolean Boolean Boolean Boolean

如果 uriString 已完全转义,则为 true;否则为 falsetrue if uriString is completely escaped; otherwise, false.

异常

baseUri 不是绝对的 Uri 实例。baseUri is not an absolute Uri instance.

通过组合 baseUrirelativeUri 而构成的 URI 为空或仅包含空格。The URI formed by combining baseUri and relativeUri is empty or contains only spaces.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的方案无效。The scheme specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 包含过多的斜杠。The URI formed by combining baseUri and relativeUri contains too many slashes.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的密码无效。The password specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的主机名无效。The host name specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的文件名无效。The file name specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的用户名无效。The user name specified in the URI formed by combining baseUri and relativeUri is not valid.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的主机名或证书颁发机构名称不能以反斜杠终止。The host or authority name specified in the URI formed by combining baseUri and relativeUri cannot be terminated by backslashes.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的端口号无效或无法分析。The port number specified in the URI formed by combining baseUri and relativeUri is not valid or cannot be parsed.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 的长度超过 65519 个字符。The length of the URI formed by combining baseUri and relativeUri exceeds 65519 characters.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中指定的方案长度超过 1023 个字符。The length of the scheme specified in the URI formed by combining baseUri and relativeUri exceeds 1023 characters.

- 或 --or- 通过组合 baseUrirelativeUri 而构成的 URI 中存在无效字符序列。There is an invalid character sequence in the URI formed by combining baseUri and relativeUri.

- 或 --or- uriString 中指定的 MS-DOS 路径必须以 c:\\ 开头。The MS-DOS path specified in uriString must start with c:\\.

示例

下面的示例创建的新实例Uri类的组合的相对 Urihttp://www.contoso.com和 Hello%20World.htm 以构成绝对 URI。The following example creates a new instance of the Uri class by combining the relative URIs http://www.contoso.com and Hello%20World.htm to form an absolute URI.

Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
Uri^ myUri = gcnew Uri( baseUri,"Hello%20World.htm",false );
Uri baseUri = new Uri("http://www.contoso.com");
Uri myUri = new Uri(baseUri, "Hello%20World.htm",false);

Dim baseUri As New Uri("http://www.contoso.com")
Dim myUri As New Uri(baseUri, "Hello%20World.htm", False)

注解

此构造函数创建Uri通过组合实例baseUrirelativeUriThis constructor creates a Uri instance by combining baseUri and relativeUri. 如果 URI 中传递relativeUri是绝对的 URI (包含一种方案、 主机名和 (可选) 端口号),Uri实例创建仅使用relativeUriIf the URI passed in relativeUri is an absolute URI (containing a scheme, host name, and optionally a port number), the Uri instance is created using only relativeUri.

dontEscape参数控制是否保留的字符将转换为转义序列。The dontEscape parameter controls whether reserved characters are translated into escape sequences. 此参数应设置为true仅当确定已转义的 URI 中的所有保留的字符。This parameter should be set to true only if you are certain that all reserved characters in the URI have been escaped. 将值设置为true为完全未转义的 URI 会导致意外的行为。Setting the value to true for a URI that has not been completely escaped can cause unexpected behavior. 强烈建议始终将此参数设置为falseIt is strongly recommended that you always set this parameter to false. 如果dontEscape设置为false,构造函数通过检查的转义任何保留的字符百分比 (%) 的所有匹配项后跟一个有效的转义序列。If dontEscape is set to false, the constructor escapes any reserved characters by checking that all occurrences of percent (%) are followed by a valid escape sequence. 如果百分号后面的字符序列不是有效的百分比是替换为 25%。If the character sequence following a percent is not valid, the percent is replaced by %25.

此构造函数不能确保Uri指的是可访问的资源。This constructor does not ensure that the Uri refers to an accessible resource.

调用方说明

出于安全考虑,您的应用程序不应调用此构造函数用于 URI 字符串来自不受信任的源和使用dontEscape设置为trueBecause of security concerns, your application should not call this constructor with URI strings from untrusted sources and with dontEscape set to true. 或者,可以通过调用检查有效性的 URI 字符串IsWellFormedOriginalString()方法之前调用此构造函数。Alternately, you can check a URI string for validity by calling the IsWellFormedOriginalString() method prior to calling this constructor.

适用于