在C#中,如何以编程方式打开特定浏览器的链接?

时间:2015-07-25 12:35:56

标签: c# browser hyperlink safari web

例如,用户有多个浏览器:Chrome,Firefox和Safari,用户的默认浏览器是Chrome。如何使代码打开用户链接时,它将使用Safari而不是默认浏览器,即Chrome?这甚至可能吗?谢谢:))

2 个答案:

答案 0 :(得分:1)

试试这个:

System.Diagnostics.Process.Start("Chrome.exe", "http://www.stackoverflow.com");//or firefox.exe

如果浏览器配置不正确,您可能会遇到异常。所以最好像这样捕获异常:

try
{
     System.Diagnostics.Process.Start("Chrome.exe", "http://www.stackoverflow.com");//or firefox.exe

}
catch(System.ComponentModel.Win32Exception noBrowser)
{
    if (noBrowser.ErrorCode == -2147467259)
       MessageBox.Show(noBrowser.Message);
}
catch (System.Exception other)
{
      MessageBox.Show(other.Message);
}

答案 1 :(得分:0)

当应用程序要启动或 Global.asax 事件时,我们应该处理这种情况,而不仅仅是我们可以重定向到任何客户端浏览器的请求。这个技巧甚至不应该尝试页面事件。

使用nameSpace并在全局页面中添加代码: process.Start()

相关问题