设置WebView2的缓存目录 [英] Set Cache directory for WebView2

查看:330
本文介绍了设置WebView2的缓存目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WPF控件中使用WebView2来承载新边缘.

I am using WebView2 in WPF control to host the new edge.

在我的代码中,我想将cookie和浏览器特定的数据缓存到缓存目录中.创建CoreWebView2Environment时,应在CoreWebView2EnvironmentOptions中设置缓存位置.

In my code, I want to cache the cookie and browser specific data to a cache directory. The cache location should be set in the CoreWebView2EnvironmentOptions when creating the CoreWebView2Environment.

有什么办法可以实现这一目标?预先感谢.

Is there any way we can achieve this ? Thanks in advance.

推荐答案

您可以在

You can set the user data folder in the CoreWebView2Environment.CreateAsync method. Its the second parameter and the other parameters may be null.

然后,您可以通过调用

You can then have the WPF WebView use your CoreWebView2Environment to create its CoreWebView2 by calling the WebView2.EnsureCoreWebView2Async method.

但是,必须在将WebView2.Source属性设置为隐式导致初始化从默认CoreWebView2Environment开始的情况下设置WebView2.Source属性之前,必须调用确保核心服务器WebView2Async.

However, you must call EnsureCoreWebView2Async before you set the WebView2.Source property as setting that property implicitly causes initialization to begin with a default CoreWebView2Environment.

您可以在 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆