我正在设计一个小型的c#应用程序,其中有一个web浏览器。我目前有我的电脑上所有的默认说谷歌chrome是我的默认浏览器,但当我点击我的应用程序中的一个链接打开一个新窗口,它打开ie浏览器。有没有办法让这些链接在默认浏览器中打开呢?还是我的电脑出了问题?

我的问题是,我在应用程序中有一个网络浏览器,所以说你去谷歌,输入“堆栈溢出”,右键单击第一个链接,单击“在新窗口中打开”,它在IE中打开,而不是Chrome。这是我编码不正确的东西,还是我的计算机上有一个设置不正确

= = = = = =进行编辑

This is really annoying. I am already aware that the browser is IE, but I had it working fine before. When I clicked a link it opened in chrome. I was using sharp develop to make the application at that time because I could not get c# express to start up. I did a fresh windows install and since I wasn't too far along in my application, I decided to start over, and now I am having this problem. That is why I am not sure if it is my computer or not. Why would IE start up the whole browser when a link is clicked rather than simply opening the new link in the default browser?


当前回答

开放的动态

string addres= "Print/" + Id + ".htm";
           System.Diagnostics.Process.Start(Path.Combine(Environment.CurrentDirectory, addres));

其他回答

public static void GoToSite(string url)
{
     System.Diagnostics.Process.Start(url);
}

这应该能解决你的问题

用当前版本的浏览器更新注册表 @“软件\ \ \ Microsoft Internet Explorer主要\ 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);

在研究了很多之后,我觉得大多数给出的答案都不适用于dotnet核心。 1. system.diagnostics.process.start(“http://google.com”);-不会工作与dotnet核心

2.它将工作,但它将阻止新窗口打开的情况下默认浏览器是chrome

 myProcess.StartInfo.UseShellExecute = true; 
    myProcess.StartInfo.FileName = "http://some.domain.tld/bla";
    myProcess.Start();

下面是最简单的,适用于所有场景。

Process.Start("explorer", url);

如果我们使用Process.Start(URL), dotnet核心将抛出一个错误。下面的代码将在dotnet核心工作。你可以添加任何浏览器,而不是Chrome。

var processes = Process.GetProcessesByName("Chrome");
var path  = processes.FirstOrDefault()?.MainModule?.FileName;
Process.Start(path,  url);

开放的动态

string addres= "Print/" + Id + ".htm";
           System.Diagnostics.Process.Start(Path.Combine(Environment.CurrentDirectory, addres));