【问题标题】:Using firefox to open c# url button not default browser使用firefox打开c#url按钮不是默认浏览器
【发布时间】:2014-08-06 10:02:58
【问题描述】:

我有一个非常简单的程序,它有 4 个按钮,每个按钮打开一个 url。 我想要的是让每个按钮都使用 Firefox 作为默认浏览器。 我知道我可以将其设置为默认浏览器,然后它将起作用,但是如果用户将 Internet Explorer 设置为默认浏览器,它将在其中打开。 这些 url 仅适用于 Firefox,因为它存在证书问题。 所以基本上我的问题是我如何更改我的代码以确保如果您单击 4 个按钮中的任何一个,它将在 Firefox 而不是 Internet Explorer 中打开。 这是我的代码

private void button1_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start("http://192.168.2.56/dummy.htm?settings=save&user_active1=on");
        BtnOff.BackColor = Color.Red;
        Bnton.BackColor = Color.Chartreuse;   
    }

    private void button2_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start("http://192.168.2.56/dummy.htm?settings=save&user_active1=off");
        Bnton.BackColor = Color.Red;
        BtnOff.BackColor = Color.Chartreuse;
    }

    private void button3_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start("https://217.20.xxx.xxx/api/agent/pause.json?active_host=217.20.xxx.xxx&active_user=3012532&username=buildstore&password=cha9pU7U&client=snom");
        BtnDND.BackColor = Color.Chartreuse;
        BtnQue.BackColor = Color.Red;
    }

    private void button4_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start("https://217.20.xxx.xxx/api/agent/unpause.json?active_host=217.20.xxx.xxx&active_user=3012532&username=buildstore&password=cha9pU7U&client=snom");
        BtnQue.BackColor = Color.Chartreuse;
        BtnDND.BackColor = Color.Red;
    }

感谢您花时间欣赏它。

【问题讨论】:

    标签: c# firefox browser


    【解决方案1】:

    你可以使用

    System.Diagnostics.Process.Start(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "http://yoursite.com/dummy.htm");
    

    您可以将 firefox.exe 的路径保留在配置文件中,而不是硬编码。或者设置 PATH 环境变量。

    【讨论】:

    • 假设他们已经在默认位置安装了Firefox,或者根本没有安装。 (This answer 可以查看注册表找到 FF 所在的位置。)
    • 不是一个稳定的解决方案,如果问题是针对 Web 应用程序提出的,则不适用于 Web 应用程序(您将在服务器而不是客户端的 PC 中启动进程)。
    • @DanKodi 不真实,这是一个应用程序。不是网站
    • 谢谢拉比这有助于分配
    • @EaterOfCode 你的意思是这是一个 Windows 应用程序而不是一个网络应用程序。
    猜你喜欢
    • 2014-12-06
    • 1970-01-01
    • 2011-05-30
    • 2016-10-21
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2020-05-06
    相关资源
    最近更新 更多