Cefsharp 清除 wpf 中的缓存、cookie 和浏览器数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47739697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cefsharp clearing cache,cookies and browser data in wpf
提问by Shervin Rafiee
I am developing an app on a banking device that uses cefsharp browser as a part of it. Cause this app will be used by anyone it should not save any data from previous user that the next user can see. I want to clear all cached browser data after closing it.
我正在银行设备上开发一个应用程序,它使用 cefsharp 浏览器作为它的一部分。因为这个应用程序将被任何人使用,它不应该保存下一个用户可以看到的前一个用户的任何数据。我想在关闭它后清除所有缓存的浏览器数据。
public void InitBrowser()
{
settings = new CefSettings();
settings.CachePath = AppDomain.CurrentDomain.BaseDirectory + "cache";
settings.CefCommandLineArgs.Add("disable-application-cache", "1");
settings.CefCommandLineArgs.Add("disable-session-storage", "1");
if (!Cef.IsInitialized) Cef.Initialize(settings);
webBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
MainGrid.Children.Add(webBrowser);
}
I want to clear all cached data after a function named WebPages_Exitis called. How can I remove all cached data without removing the browser instance or shutting down the CEF cause CEF can't be initialized twice and creating another instance of browser after disposing it is not working.
我想在WebPages_Exit调用一个名为的函数后清除所有缓存的数据 。如何在不删除浏览器实例或关闭 CEF 的情况下删除所有缓存数据,因为 CEF 无法初始化两次,并且在处理后创建另一个浏览器实例不起作用。
I implemented visitfunction in ICookieVisitorto save cookies as well and used methods like deleteCookiesor disabling cache cefSetting command, but nothing works cause cookies list is empty and visitfunction of IcookieVisitoris never called. it seems that it is saved in another part and just resets when CEF will shutdown.
我也实现visit了ICookieVisitor用于保存 cookie 的函数,并使用了诸如deleteCookies或禁用缓存 cefSetting 命令之类的方法,但没有任何作用,因为 cookie 列表为空并且从未调用过visit函数IcookieVisitor。它似乎保存在另一部分,只是在 CEF 关闭时重置。
回答by Shervin Rafiee
I found the answer! it was because of disabling cache setting.
with disabling cache setting it actually caches the data but it won't be accessible for example you can't remove cookies without shutting down the CEF. so if you enable cache setting (leave it as default setting) you can remove them with Cef.GetGlobalCookieManager().DeleteCookies("", "")method.
我找到了答案!这是因为禁用缓存设置。禁用缓存设置后,它实际上会缓存数据,但无法访问它,例如您无法在不关闭CEF. 因此,如果您启用缓存设置(将其保留为默认设置),您可以使用Cef.GetGlobalCookieManager().DeleteCookies("", "")方法删除它们。

