1、设置cookie
var cookieManager = CefSharp.Cef.GetGlobalCookieManager();
await cookieManager.SetCookieAsync("http://" + domain, new CefSharp.Cookie()
{
Domain = domain,
Name = name,
Value = value,
Expires = DateTime.MinValue
});
2、读取cookie
1) 创建Cookie读取对象,继承接口 ICookieVisitor
public class CookieVisitor : CefSharp.ICookieVisitor
{
public event Action<CefSharp.Cookie> SendCookie;
public bool Visit(CefSharp.Cookie cookie, int count, int total, ref bool deleteCookie)
{
deleteCookie = false;
if (SendCookie != null)
{
SendCookie(cookie);
}
return true;
}
}
2) 在browser事件中进行处理
private void browser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
{
var cookieManager = CefSharp.Cef.GetGlobalCookieManager();
CookieVisitor visitor = new CookieVisitor();
visitor.SendCookie += visitor_SendCookie;
cookieManager.VisitAllCookies(visitor);
}
/// 回调事件
private void visitor_SendCookie(CefSharp.Cookie obj)
{
cookies += obj.Domain.TrimStart('.') + "^" + obj.Name + "^" + obj.Value + "$";
}
相关文档:
https://github.com/cefsharp/CefSharp/wiki/Quick-Start
.Net(C#) cefsharp Chrome 浏览器控件后台执行Iframe中的Js代码的方法
.NET(C#) cefsharp 设置浏览器默认语言和userAgent及示例代码