CefSharp Wpf , Session Cookie for multiple instances

杀马特。学长 韩版系。学妹 提交于 2019-12-07 04:16:25

As of revision 2040, CEF now adds support for complete isolation of storage and permissions (cache, cookies, localStorage, access grants, etc) on a request context basis. This is also now in CEFSharp.

To make sure that no sessions overlap between multiple instances, simply create a new RequestContextSettings object, set PersistSessionCookies and/or PersistUserPreferences to false, and assign it to your browser while creating a new RequestContext - I am not sure if setting them to false is completely necessary for multiple instances, maybe someone else can give some info on that.

//usually ChromiumWebBrowser setup goes above this

RequestContextSettings requestContextSettings = new RequestContextSettings();

requestContextSettings.PersistSessionCookies = false;
requestContextSettings.PersistUserPreferences = false;

webBrowser.RequestContext = new RequestContext(requestContextSettings);

This had been giving me headaches for a while and this appears to finally solve that issue.

Just use this code, its working for me.

public MainWindow()
    {
        CefSharp.CefSettings settings = new CefSharp.CefSettings();
        settings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\CEF"; 
       CefSharp.Cef.Initialize(settings);

        InitializeComponent();
        browser = new ChromiumWebBrowser("https://google.com/");
        browser.BrowserSettings.ApplicationCache = CefSharp.CefState.Disabled;

    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!