.net 6中使用Process.Start()打开url时提示找不到文件

在 .net framework时代,如果想使用默认浏览器打开一个url可以使用以下代码:

System.Diagnostics.Process.Start("https://www.baidu.com?wd=key");

但该代码在.net 6中执行会出错,提示系统找不到指定文件。

原因是.net core改变了ProcessStartInfo类的默认值,在默认情况下UseShellExecute的取值为False,而.net framework中取值为True。
所以,要解决该报错只需将UseShellExecute设置为True即可:

System.Diagnostics.Process.Start(new ProcessStartInfo("https://www.baidu.com?wd=key"){UseShellExecute=true});

上一篇:没有了

下一篇:asp.net core由于大小写出现的问题