.Net Core 3.1 Process.Start(“www.website.com”) not working in WPF

﹥>﹥吖頭↗ 提交于 2020-07-15 08:17:55

问题


I am using .Net Core 3.1 Framework in WPF Application. I have a button event in which I am trying to redirect to Instagram url on click. but its giving me the following error.

Exception thrown: 'System.ComponentModel.Win32Exception' in System.Diagnostics.Process.dll.

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

回答1:


You have to change you code per follows

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

UseShellExecute property is set to false in .NET Core by default, to open https:// link you have to set it to true, because it isn't an executable file



来源:https://stackoverflow.com/questions/59716856/net-core-3-1-process-startwww-website-com-not-working-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!