Cómo abrir en el navegador predeterminado en C#


Estoy diseñando una pequeña aplicación de C# y hay un navegador web en ella. Actualmente tengo todos mis valores predeterminados en mi computadora dicen Google Chrome es mi navegador predeterminado, sin embargo, cuando hago clic en un enlace en mi aplicación para abrir en una nueva ventana, se abre Internet explorer. ¿Hay alguna manera de hacer que estos enlaces se abran en el navegador predeterminado? ¿O hay algo mal en mi computadora?

Mi problema es que tengo un navegador web en la aplicación, así que digamos que vas a Google y escribes " stack desbordamiento "y haga clic derecho en el primer enlace y haga clic en" Abrir en nueva ventana " se abre en IE en lugar de Chrome. ¿Es esto algo que he codificado incorrectamente, o hay una configuración no correcta en mi computadora

===EDITAR===

Esto es realmente molesto. Ya soy consciente de que el navegador es IE, pero lo tenía funcionando bien antes. Cuando hice clic en un enlace se abrió en Chrome. Estaba usando sharp develop para hacer la aplicación en ese momento porque no podía hacer que c # express se iniciara. Hice un instalación de windows fresco y ya que no estaba demasiado lejos en mi aplicación, decidí empezar de nuevo, y ahora estoy teniendo este problema. Es por eso que no estoy seguro si es mi computadora o no. ¿Por qué IE iniciaría todo el navegador cuando se hace clic en un enlace en lugar de simplemente abrir el nuevo enlace en el navegador predeterminado?

Author: Sean, 2011-01-02

10 answers

Puedes escribir

System.Diagnostics.Process.Start("http://google.com");

EDITAR : El control WebBrowser es una copia incrustada de IE.
Por lo tanto, cualquier enlace dentro de él se abrirá en IE.

Para cambiar este comportamiento, puede manejar el evento Navigating.

 406
Author: SLaks,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-14 14:21:58
public static void GoToSite(string url)
{
     System.Diagnostics.Process.Start(url);
}

Eso debería resolver tu problema

 28
Author: user2193090,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-02 13:18:16

Para aquellos que encuentran esta pregunta en dotnet core. He encontrado una solución aquí

Código:

private void OpenUrl(string url)
{
    try
    {
        Process.Start(url);
    }
    catch
    {
        // hack because of this: https://github.com/dotnet/corefx/issues/10361
        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            url = url.Replace("&", "^&");
            Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
        {
            Process.Start("xdg-open", url);
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
        {
            Process.Start("open", url);
        }
        else
        {
            throw;
        }
    }
}
 16
Author: Joel Harkes,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-05 13:20:55

¿try Processcomo se menciona aquí: http://msdn.microsoft.com/de-de/library/system.diagnostics.process.aspx?

Podrías usar

Process myProcess = new Process();

try
{
    // true is the default, but it is important not to set it to false
    myProcess.StartInfo.UseShellExecute = true; 
    myProcess.StartInfo.FileName = "http://some.domain.tld/bla";
    myProcess.Start();
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
}
 12
Author: Andreas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-01-02 20:19:01

Echa un vistazo al control GeckoFX.

GeckoFX es un componente de código abierto lo que facilita la integración de Mozilla Gecko (Firefox) en cualquier Windows. NET Formularios de solicitud. Escrito en limpio, completamente comentado C#, GeckoFX es el reemplazo perfecto para el defecto Navegador web basado en Internet Explorer control.

 5
Author: THE DOCTOR,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-01-02 20:37:20

Esto abrió el valor predeterminado para mí:

System.Diagnostics.Process.Start(e.LinkText.ToString());
 3
Author: Xero Phane,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-21 08:02:42

Prueba esto, a la vieja usanza;)

public static void openit(string x)
    {
        System.Diagnostics.Process.Start("cmd", "/C start" + " " + x);
    }

Usando: openit("www.google.com");

 0
Author: Moh.Kirkuk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-28 04:53:56

En UWP:

await Launcher.LaunchUriAsync(new Uri("http://google.com"));
 0
Author: Kibernetik,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-29 14:14:57

Abrir dinámicamente

string addres= "Print/" + Id + ".htm";
           System.Diagnostics.Process.Start(Path.Combine(Environment.CurrentDirectory, addres));
 0
Author: سیدرسول میرعظیمی,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-22 06:58:55

Actualizar el registro con la versión actual de explorer
@"Software \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BROWSER_EMULATION"

public enum BrowserEmulationVersion
{
    Default = 0,
    Version7 = 7000,
    Version8 = 8000,
    Version8Standards = 8888,
    Version9 = 9000,
    Version9Standards = 9999,
    Version10 = 10000,
    Version10Standards = 10001,
    Version11 = 11000,
    Version11Edge = 11001
}

key.SetValue(programName, (int)browserEmulationVersion, RegistryValueKind.DWord);
 0
Author: dfgv,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-08 06:09:51