众所周知,使用System.Diagnostics.Process.Start是从C#应用程序启动url的方式:
System.Diagnostics.Process.Start(“ http://www.mywebsite.com”);
但是,如果此url无效,则应用程序似乎无法知道调用失败或原因。有没有更好的方法来启动网络浏览器?如果不是,我对URL验证的最佳选择是什么?
请您参考如下方法:
请尝试以下方法。
try
{
var url = new Uri("http://www.example.com/");
Process.Start(url.AbsoluteUri);
}
catch (UriFormatException)
{
// URL is not parsable
}
这不能确保资源存在,但是可以确保URL格式正确。您可能还想检查该方案是否匹配http或https。
