Separate cache per browser?

二次信任 提交于 2019-12-21 17:16:09

问题


Currently I'm setting the cache path as follows:

CefSettings settings = new CefSettings();
settings.CachePath = mycachePath;

Cef.Initialize(settings);

var browser = new ChromiumWebBrowser(myUrl);

The above works.

However, I need to login to a website with 2 different accounts simultaneously but it uses the same cookie container. So if I login with one account and then the other, the first account is overridden.

Is it possible to have a have a cache path per browser?

Or is there a better way to handle this situation?


回答1:


It looks like you're using CefSharp? If so, looking through the code, it seems that you want to create the browser with an empty CachePath:

/// <summary>
/// Returns the cache path for this object. If empty an "incognito mode"
/// in-memory cache is being used.
/// </summary>
string CachePath { get; }

Looking at their sample (I'm assuming windowless), this looks like it'll get roughly what you want:

var browserSettings = new BrowserSettings();
var requestContextSettings = new RequestContextSettings { CachePath = "" };

using(var requestContext = new RequestContext(requestContextSettings))
using (var browser = new ChromiumWebBrowser(TestUrl, browserSettings, requestContext))
{
    ...
}


来源:https://stackoverflow.com/questions/34549565/separate-cache-per-browser

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