.Net Core 3.1 Process.Start(“www.website.com") 在 WPF 中不起作用 [英] .Net Core 3.1 Process.Start("www.website.com") not working in WPF
问题描述
我在 WPF 应用程序中使用 .Net Core 3.1 框架.我有一个按钮事件,我试图在点击时重定向到 Instagram 网址.但它给了我以下错误.
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.
抛出异常:System.Diagnostics.Process.dll 中的System.ComponentModel.Win32Exception".
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
{
}
}
推荐答案
您必须根据以下内容更改代码
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
属性在 .NET Core 中默认设置为 false
,打开 https://
链接你必须设置它true
,因为它不是可执行文件
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
这篇关于.Net Core 3.1 Process.Start(“www.website.com") 在 WPF 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!