CefSharp Wpf , Session Cookie for multiple instances

耗尽温柔 提交于 2019-12-08 08:20:50

问题


I am very curious if there is a possibility in CEF Sharp , somehow to isolate each instance of browser from other instances.

I am creating 4 instances of browser. Logging in on of the instances , immediately 3 other instances become logged in as well.

Is it possible to achieve somehow in Current version that we got from Nuget ?


回答1:


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.




回答2:


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;

    }


来源:https://stackoverflow.com/questions/40451702/cefsharp-wpf-session-cookie-for-multiple-instances

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