如何使用 Microsoft WebView2 同时登录多个帐户
How to login to multiple account at same time with Microsoft WebView2
我创建了一个带有 webview2 控件的应用程序 运行 它并使用用户 A 登录到我的网站,然后再次 运行 我的应用程序而不关闭前一个实例并使用用户登录B在同一个网站,则登录成功。当我检查前一个实例时,用户 A 仍处于登录状态。如何在一个实例应用程序上以相同的方式执行操作?我已经用两个 webview2 控件尝试过,当我用用户 B 登录时,用户 A 被注销或者会话被用户 B 替换。
WebVeiw2 使用 user data folder 存储 cookie。
要在不同的会话中启动另一个控件实例,作为一个选项,您可以设置UserDataFolder,例如:
private async void button1_Click(object sender, EventArgs e)
{
webView21.CreationProperties =
new Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties();
webView21.CreationProperties.UserDataFolder = System.IO.Path.Combine(
Application.StartupPath, $"{Guid.NewGuid()}");
await webView21.EnsureCoreWebView2Async();
webView21.CoreWebView2.Navigate("https://outlook.com");
}
对于那些想开始使用 WebView2, you need to have WebView2 Runtime and Microsoft Edge Chromium installed on your machine. You also need to install WebView2 NuGet package in your project. Then you can start here: Getting started with WebView2 in Windows Forms 的人。
我创建了一个带有 webview2 控件的应用程序 运行 它并使用用户 A 登录到我的网站,然后再次 运行 我的应用程序而不关闭前一个实例并使用用户登录B在同一个网站,则登录成功。当我检查前一个实例时,用户 A 仍处于登录状态。如何在一个实例应用程序上以相同的方式执行操作?我已经用两个 webview2 控件尝试过,当我用用户 B 登录时,用户 A 被注销或者会话被用户 B 替换。
WebVeiw2 使用 user data folder 存储 cookie。
要在不同的会话中启动另一个控件实例,作为一个选项,您可以设置UserDataFolder,例如:
private async void button1_Click(object sender, EventArgs e)
{
webView21.CreationProperties =
new Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties();
webView21.CreationProperties.UserDataFolder = System.IO.Path.Combine(
Application.StartupPath, $"{Guid.NewGuid()}");
await webView21.EnsureCoreWebView2Async();
webView21.CoreWebView2.Navigate("https://outlook.com");
}
对于那些想开始使用 WebView2, you need to have WebView2 Runtime and Microsoft Edge Chromium installed on your machine. You also need to install WebView2 NuGet package in your project. Then you can start here: Getting started with WebView2 in Windows Forms 的人。