1

我很好奇 CEF Sharp 是否有可能以某种方式将浏览器的每个实例与其他实例隔离开来。

我正在创建 4 个浏览器实例。登录实例后,其他 3 个实例也立即登录。

是否有可能在我们从 Nuget 获得的当前版本中以某种方式实现?

4

2 回答 2

6

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.

于 2017-06-27T03:44:35.830 回答
-2

只需使用此代码,它对我有用。

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;

    }
于 2017-04-27T07:23:12.437 回答