I have a website and users can login there to access their personal profiles. In google chrome or another web browser I can open the site and login there. To logout the website sends a request to my web api. After closing the tab without logging out I load my site in the new tab and it asks me to log. It is a good behaviour.
But when I open this site in CefSharp Chromium Browswer (CefSharp.WinForms 79.1.360) I can't automatically logout the user. I use the next method to clear all the data and after that I load start page:
await Cef.GetGlobalCookieManager().DeleteCookiesAsync(string.Empty, string.Empty);
my settings are:
Cef.EnableHighDPISupport();
CefSharpSettings.LegacyJavascriptBindingEnabled = true;
CefSharpSettings.WcfEnabled = true;
var settings = new CefSettings();
settings.CefCommandLineArgs.Remove("disable-gpu-compositing");
Cef.Initialize(settings);
I use next handlers:
Browser = new ChromiumWebBrowser(ConfigProvider.HomeUrl)
{
KeyboardHandler = new KeyboardHandler(),
RequestHandler = new RequestHandler(),
LifeSpanHandler = new LifeSpanHandler(_popupUrlsWhiteList),
MenuHandler = new MenuHandler(),
DownloadHandler = downloadHandler
};
But the user isn't logged out. I tried to store cache in the local folder (using CefSettings) but it also didnt't work.
This method works for many sites which use cookies to store the logged in user. After I clear cookies they are automatically logged out. But for this site it doesn't work. This site doesn't use cookies to store loging info, logging out is performed through their web api. This site is not actually mine and I don't have the source code.
Can I somehow make CefSharp to clear session in the browser like the regular google chrome does when closing a tab ?
User is logged out by pressing button on the site's header and a http request is sent to server to log out the user.
I could make the user to be logged out automatically by Browser.GetMainFrame().ExecuteJavaScriptAsync(JsMethods.GetClearSessionMethod())
which just do the simple job:
localStorage.clear();
sessionStorage.clear();
The problem was that user "logged info" was stored in sessionStorage and it wasn't cleared by calling
await Cef.GetGlobalCookieManager().DeleteCookiesAsync(string.Empty, string.Empty);