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.

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

参数

uriString
String String String

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

uriKind
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. 如果启用了国际资源标识符 (Iri) 或国际化域名 (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 开始,始终认为字符串的格式正确的根据 RFC 3986 和 RFC 3987,该值指示是否 IRI 或 IDN 启用。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.

则认为字符串的格式很差,并导致此方法返回 false,如果出现任何以下条件The string is considered poorly formed, causing the method to return false, if any of the following conditions occur

ErrorError 示例Example
未正确转义字符串。The string is not correctly escaped. http://www.contoso.com/path???/file 名称http://www.contoso.com/path???/file name
字符串是绝对Uri,表示隐式文件UriThe string is an absolute Uri that represents an implicit file Uri. c:\\directory\filenamec:\\directory\filename
该字符串是缺少斜杠之前路径的绝对 URI。The string is an absolute URI that is missing a slash before the path. file://c:/directory/filenamefile://c:/directory/filename
该字符串包含非转义反斜杠,即使将被视为正斜杠The string contains unescaped backslashes even if they will be treated as forward slashes http:\\host/path/filehttp:\\host/path/file
该字符串表示层次结构的绝对Uri,并且不包含"://"The string represents a hierarchical absolute Uri and does not contain "://" www.contoso.com/path/filewww.contoso.com/path/file
分析器Scheme指示原始字符串不是格式正确。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:412013.05.29_14:33:41

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

适用于

另请参阅