我正在尝试使用Uri.TryCreate方法验证一个URI,但当我使用一个无效的字符串调用它时,该方法返回了true。有什么想法吗?我的代码如下:
private void button1_Click(object sender, EventArgs e)
{
Uri tempValue;
if (Uri.TryCreate("NotAURL", UriKind.RelativeOrAbsolute, out tempValue))
{
MessageBox.Show("?");
}
}
http://example.com/
,那么这个相对URL指的是http://example.com/NotAURL
。 - Matthew Flaschenhttp://example.org/foo/bar.html
,那么空的相对路径引用相同的文件。相对路径?
也指向带有空查询字符串的相同文件;如果原始 URL 已经有查询字符串,则新的查询字符串将替换旧的查询字符串。例如,从http://example.org/foo/bar.html?foo=bar
开始,相对 URL?baz=qux
产生http://example.org/foo/bar.html?baz=qux
。(空的相对 URL 保留原始查询字符串。) - Mike Rosoft