Uri.TryCreate任何字符串值返回true? [英] Uri.TryCreate returns true for any string value?
本文介绍了Uri.TryCreate任何字符串值返回true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想验证使用Uri.TryCreate方法的URI,当我与一个无效的字符串称之为,该方法返回真。任何想法,为什么?我的代码如下:
私人无效的button1_Click(对象发件人,EventArgs五)
{
乌里tempValue ;
如果(Uri.TryCreate(NotAURL,UriKind.RelativeOrAbsolute,出tempValue))
{
MessageBox.Show(?);
}
}
解决方案
这是一个有效的相对URL。一个无效的URI的一个例子是:
的http://example.com<>中
如果您希望只允许绝对URI,使用 UriKind.Absolute
。
然后,该示例将无法解析。
I'm trying to validate a Uri using the Uri.TryCreate method and when I called it with an invalid string, the method returned true. Any ideas why? My code is below:
private void button1_Click(object sender, EventArgs e)
{
Uri tempValue;
if (Uri.TryCreate("NotAURL", UriKind.RelativeOrAbsolute, out tempValue))
{
MessageBox.Show("?");
}
}
解决方案
That's a valid relative URL. An example of a invalid URI is:
"http://example.com<>"
If you want to allow only absolute URIs, use UriKind.Absolute
.
The example will then fail to parse.
这篇关于Uri.TryCreate任何字符串值返回true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文