删除在C# .NET中的WPF Webview2缓存中的登录凭据和历史记录?

huangapple go评论175阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月5日 13:20:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403648.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定