.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
属性设置为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屋!