.core2.1 控制台打开系统浏览器

mirrorspace 2020-01-08 12:10:03
如题:
.net core2.1控制台程序如何打开系统浏览器,并且打开localhost:8000?
...全文
244 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
mirrorspace 2020-01-09
  • 打赏
  • 举报
回复
OK! 解决了问题!
github_36000833 2020-01-09
  • 打赏
  • 举报
回复
引用 3 楼 mirror030 的回复:
...有没有办法打开指定的谷歌浏览器呢?假如已经安装了...
那首先你要找到‘指定的谷歌浏览器’,比如在: var chromeExe = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"; 然后就: Process.Start(chromeExe, url).Dispose();
github_36000833 2020-01-08
  • 打赏
  • 举报
回复
class Program { static void Main(string[] args) { // Windows下可以用Shell var startInfo = new ProcessStartInfo("http://localhost:8000") { UseShellExecute = true}; Process.Start(startInfo).Dispose(); } }
mirrorspace 2020-01-08
  • 打赏
  • 举报
回复
是的大神 可以了,打开了本机的默认浏览器! win下的IE太烂了,有没有办法打开指定的谷歌浏览器呢?假如已经安装了
引用 2 楼 github_36000833 的回复:
假定当前用户有交互桌面。Windows可以用ShellExecute,MacOS可以用open,Linux可以用xdg-open。
static void Main(string[] args)
{
    var url = "http://localhost:8000";
    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
    {
        Process.Start("xdg-open", url).Dispose();
    }
    else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
    {
        Process.Start("open", url).Dispose();
    }
    else
    {
        Process.Start(new ProcessStartInfo(url) { UseShellExecute = true}).Dispose();
    }
}
github_36000833 2020-01-08
  • 打赏
  • 举报
回复
假定当前用户有交互桌面。Windows可以用ShellExecute,MacOS可以用open,Linux可以用xdg-open。
static void Main(string[] args)
{
    var url = "http://localhost:8000";
    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
    {
        Process.Start("xdg-open", url).Dispose();
    }
    else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
    {
        Process.Start("open", url).Dispose();
    }
    else
    {
        Process.Start(new ProcessStartInfo(url) { UseShellExecute = true}).Dispose();
    }
}

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧