英文:
Deleting login credentials and history from WPF webview2 cache in C# .NET?
问题
清除 WPF webview2 的缓存内存在运行时
我正在尝试删除 WPF webview2 存储的缓存内存,我已经定义了用户文件夹,但找不到删除用户文件夹的合适方法。
我不想释放 webview2,因为除了缓存内存之外,它还会丢失其他信息。
我只想删除 webview2 的登录凭据和历史记录。
async void WebFullSCreenInitialize()
{
string browseExe = exePath + "\\Microsoft.WebView2";
string cacheFolder = exePath + "\\Cache";
var op = new CoreWebView2EnvironmentOptions("--disable-web-security ; --autoplay-policy=no-user-gesture-required");
var env = await CoreWebView2Environment.CreateAsync(browseExe, cacheFolder, op);
await externalWebFullSCreen.EnsureCoreWebView2Async(env);
}
英文:
Clear the cache memory of webview2 WPF while runtime
I am trying to delete the cache memory stored by WPF webview2, I am defining the userfolder but not finding any proper method to delete the userfolder.
I don't want to dispose the webview2 as it will loose some other information apart from cache memory
I just want to delete the login credentials and history of webview2
async void WebFullSCreenInitialize()
{
string browseExe = exePath + "\\Microsoft.WebView2";
string cacheFolder = exePath + "\\Cache";
var op = new CoreWebView2EnvironmentOptions("--disable-web-security ; --autoplay- policy=no-user-gesture-required");
var env = await CoreWebView2Environment.CreateAsync(browseExe, cacheFolder, op);
await externalWebFullSCreen.EnsureCoreWebView2Async(env);
}
答案1
得分: 0
在WPF中,您可以在运行时清除Webview2创建的缓存文件夹。只需在特定事件上调用一个方法
public void clearCacheWebview()
{
externalWebFullSCreen.CoreWebView2.Profile.ClearBrowsingDataAsync();
externalWebFullSCreen.Source = new Uri("清除缓存后的URL");
}
确保您正在使用最新版本的webview,因为CoreWebView2.Profile.ClearBrowsingDataAsync方法仅适用于最新版本。
英文:
In WPF you can clear the cache folder create by Webview2 at runtime. On specific event just call a method
public Void clearCacheWebview()
{
externalWebFullSCreen.CoreWebView2.Profile.ClearBrowsingDataAsync();
externalWebFullSCreen.Source = new URI("your url after clearing thecache");
}
Make sure you are using the latest webview version as CoreWebView2.Profile.ClearBrowsingDataAsync is available to latest version.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论