Uri.IsWellFormedUriString(String, UriKind) Uri.IsWellFormedUriString(String, UriKind) Uri.IsWellFormedUriString(String, UriKind) Method


通过尝试用字符串构造一个 URI 来指示字符串是否为格式良好的,并确保字符串不需要进一步转义。Indicates whether the string is well-formed by attempting to construct a URI with the string and ensures that the string does not require further escaping.

 static bool IsWellFormedUriString(System::String ^ uriString, UriKind uriKind);
public static bool IsWellFormedUriString (string uriString, UriKind uriKind);
static member IsWellFormedUriString : string * UriKind -> bool


String String String

用于尝试构造 Uri 的字符串。The string used to attempt to construct a Uri.

UriKind UriKind UriKind

Uri 中的 uriString 的类型。The type of the Uri in uriString.


如果该字符串格式正确,则为 true;否则为 falsetrue if the string was well-formed; otherwise, false.


在版本4.5 之前的 .NET 版本中,默认情况下,根据 RFC 2396 和 RFC 2732,将字符串视为格式正确。In versions of .NET before version 4.5, by default the string is considered well-formed in accordance with RFC 2396 and RFC 2732. 如果启用了 "国际资源标识符(IRIs)" 或 "国际化域名(IDN)分析",则根据 RFC 3986 和 RFC 3987,字符串将被视为格式正确。If International Resource Identifiers (IRIs) or Internationalized Domain Name (IDN) parsing are enabled, the string is considered well-formed in accordance with RFC 3986 and RFC 3987.

从 .NET 4.5 开始,无论是否启用了 IRI 或 IDN,字符串始终根据 RFC 3986 和 RFC 3987 被视为格式正确。Beginning in .NET 4.5, strings are always considered well-formed in accordance with RFC 3986 and RFC 3987, whether or not IRI or IDN are enabled. 但请注意,这仅适用于面向 .NET 4.5 或更高版本的应用程序。Note, however, that this is only true for apps that target .NET 4.5 or later. 面向 .NET 4.0 的应用程序会调用兼容性代码,并体验旧的(4.5 之前)的行为。Apps that target .NET 4.0 invoke compatibility code, and experience the old (pre-4.5) behavior.

如果出现下列任一情况,字符串将被视为格式不正确,从而导致方法返回 falseThe string is considered poorly formed, causing the method to return false, if any of the following conditions occur

错误Error 示例Example
字符串未正确转义。The string is not correctly escaped. http://www.contoso.com/path???/file name
字符串是一个绝对 Uri,它表示 Uri 的隐式文件。The string is an absolute Uri that represents an implicit file Uri. c:\\directory\filename
字符串是一个绝对 URI,它在路径之前缺少一个斜杠。The string is an absolute URI that is missing a slash before the path. file://c:/directory/filename
该字符串包含非转义反斜杠,即使它们将被视为正斜杠The string contains unescaped backslashes even if they will be treated as forward slashes http:\\\host/path/file
该字符串表示层次结构的绝对 Uri,并且不包含 "://"The string represents a hierarchical absolute Uri and does not contain "://" www.contoso.com/path/file
@No__t 的分析器表示原始字符串格式不正确。The parser for the Scheme indicates that the original string was not well-formed. 该示例取决于 URI 的方案。The example depends on the scheme of the URI.
从 .NET 4.5 开始,第一段中带有冒号(":")的相对 Uri 不被视为格式正确。Beginning with .NET 4.5, relative URIs with a colon (':') in their first segment are not considered well-formed. 2013.05.29_14:33:41

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