【问题标题】:.Net Core 3.1 Process.Start("www.website.com") not working in WPF.Net Core 3.1 Process.Start("www.website.com") 在 WPF 中不起作用
【发布时间】:2020-01-13 12:40:35
【问题描述】:

我在 WPF 应用程序中使用 .Net Core 3.1 Framework。我有一个按钮事件,我试图在点击时重定向到 Instagram url。但它给了我以下错误。

抛出异常:System.Diagnostics.Process.dll 中的“System.ComponentModel.Win32Exception”。

private void Insta_Click(object sender, RoutedEventArgs e)
{
    try
    {
        string targetURL = "https://www.instagram.com/xyz/";
        Process.Start(targetURL);
    }
    catch
    {
    }
}

【问题讨论】:

  • 异常信息是什么?

标签: c# wpf .net-core process


【解决方案1】:

您必须根据关注更改您的代码

var targetURL = "https://www.instagram.com/xyz/";
var psi = new ProcessStartInfo
{
    FileName = targetURL,
    UseShellExecute = true
};
Process.Start(psi);

UseShellExecute 属性在.NET Core 中默认设置为false,要打开https:// 链接,您必须将其设置为true,因为它不是可执行文件

【讨论】:

  • 感谢您解决了我的问题。我错过了我不知道的 UseShellExecute = true。
猜你喜欢
  • 2021-10-22
  • 1970-01-01
  • 2023-03-02
  • 1970-01-01
  • 2010-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-25
相关资源
最近更新 更多