是否有净的URL验证? [英] Is there a URL validator on .Net?

查看:129
本文介绍了是否有净的URL验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有以验证在.NET中,ASP.Net,或ASP.Net MVC URL的方法?

Is there a method to validate URLs in .Net, ASP.Net, or ASP.Net MVC?

推荐答案

您可以使用<$c$c>Uri.TryCreate验证一个网址:

You can use the Uri.TryCreate to validate an URL:

public bool IsValidUri(string uri)
{
    Uri validatedUri;
    return Uri.TryCreate(uri, UriKind.RelativeOrAbsolute, out validatedUri);
}

的意见建议 TryCreate 只是移动异常处理向下一个级别。然而,我检查源$ C ​​$ c和发现这种情况并非如此。里面有 TryCreate 没有try / catch语句,它使用一个自定义的解析器不应该抛出。

The comments suggest that TryCreate just moves the exception handling one level down. However, I checked the source code and found that this is not the case. There is no try/catch inside TryCreate, it uses a custom parser which should not throw.

这篇关于是否有净的URL验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆