问题描述
我正在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.
推荐答案
您可以在 CoreWebView2Environment.CreateAsync 方法.它的第二个参数和其他参数可以为空.
You can set the user data folder in the CoreWebView2Environment.CreateAsync method. Its the second parameter and the other parameters may be null.
然后,您可以通过调用 WebView2.EnsureCoreWebView2Async方法.
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.
您可以在 WebView2文档摘要部分.
这篇关于设置WebView2的缓存目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!