WebVeiw2 使用用户数据文件夹来存储 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");
}
Run Code Online (Sandbox Code Playgroud)
对于那些想要开始使用WebView2 的人,您需要在您的机器上安装WebView2 Runtime和Microsoft Edge Chromium。您还需要在您的项目中安装WebView2 NuGet 包。然后您可以从这里开始:Windows 窗体中的 WebView2 入门。