13
我想使用Uri.TryCreate方法验证Uri,当我用无效字符串调用它时,该方法返回true。任何想法为什么?我的代码如下:Uri.TryCreate对任何字符串值都返回true?
private void button1_Click(object sender, EventArgs e)
{
Uri tempValue;
if (Uri.TryCreate("NotAURL", UriKind.RelativeOrAbsolute, out tempValue))
{
MessageBox.Show("?");
}
}
有趣的,我想我没有把它当作一个文件夹。我试图验证网站网址,所以我没有考虑文件夹路径。谢谢! – 2010-11-12 03:03:05
它可能是网站上的相对URI。例如。如果你使用'http:// example.com /',那么这个相对URL就是指'http:// example.com/NotAURL'。 – 2010-11-12 03:06:01
是的,这就是我所做的 - 将它切换到UriKind.Absolute。再次感谢。 – 2010-11-12 03:17:32