/// <summary> /// 清除cookies /// </summary> /// <param name="urls"></param> /// <param name="names"></param> public static void DelectCookie(string domain, List <string> names) { CefCookieManager manager = CefCookieManager.GetGlobal(null); string url = "http://" + domain; foreach (var name in names) { manager.DeleteCookies(url, name, null); } }
public RequestContextHandler(DirectoryInfo cookieDirectory = null) { if (cookieDirectory != null) { this.CookieManager = CefCookieManager.Create(cookieDirectory.FullName, false); } else { this.CookieManager = CefCookieManager.Create(null, false); } }
/// <summary> /// The on before close. /// </summary> public void OnBeforeClose() { BeforeClose?.Invoke(this, null); // Flush cache // This is needed since there is some delay from when a cookie // has been set/deleted before it is actually persisted to disk. // This ensures all cookies is written to disk before exit. var cookieManager = CefCookieManager.GetGlobal(null); cookieManager?.FlushStore(null); }
public static async Task <Cookie[]> GetCookies(string domainEnding) { var manager = CefCookieManager.GetGlobal(null); var visitor = new CookieVisitor(); if (!manager.VisitAllCookies(visitor)) { return(new Cookie[0]); } var cc = await visitor.Task; return((await visitor.Task).Where(c => c.Domain.EndsWith(domainEnding)).ToArray()); }
/// <summary> /// Sets a cookie given a valid URL and explicit user-provided cookie attributes. /// This function expects each attribute to be well-formed. It will check for disallowed /// characters (e.g. the ';' character is disallowed within the cookie value attribute) and will return false without setting /// </summary> /// <param name="cookieManager">cookie manager</param> /// <param name="url">The cookie URL. If an empty string is provided, any URL will be matched.</param> /// <param name="cookie">the cookie to be set</param> /// <returns>returns false if the cookie cannot be set (e.g. if illegal charecters such as ';' are used); /// otherwise task that represents the set operation. The value of the TResult parameter contains a bool to indicate success.</returns> public static Task <bool> SetCookieAsync(this CefCookieManager cookieManager, string url, CefNetCookie cookie) { if (cookieManager == null) { throw new NullReferenceException("cookieManager"); } if (cookieManager.IsDisposed) { throw new ObjectDisposedException("cookieManager"); } var callback = new TaskSetCookieCallback(); if (cookieManager.SetCookie(url, cookie, callback)) { return(callback.Task); } //There was a problem setting cookies return(Task.FromResult(false)); }
/// <summary> /// 设置cookies /// </summary> /// <param name="urls"></param> /// <param name="cookies"></param> /// <param name="domain"></param> public static void SetCookie(string domain, Dictionary <string, string> cookies) { CefCookieManager manager = CefCookieManager.GetGlobal(null); string url = "http://" + domain; foreach (var c in cookies) { CefCookie cookie = new CefCookie(); cookie.Name = c.Key; cookie.Value = c.Value; cookie.Domain = domain; cookie.Path = "/"; cookie.HttpOnly = false; //cookie.Expires = DateTime.Now.AddDays(100); //cookie.expires.year = 2200; //cookie.expires.month = 4; //cookie.expires.day_of_week = 5; //cookie.expires.day_of_month = 11; // BSCookieTask bt = new BSCookieTask(url, cookie); //CefRuntime.PostTask(CefThreadId.IO, bt); manager.SetCookie(url, cookie, null); } }
public bool SetCookie(string name, string value, string domain, string path, bool httpOnly, bool secure, DateTime?expires, bool global) { // Reset the wait event. _setCookieEvent.Reset(); var success = false; // Set the cookie on the IO thread. CefRuntime.PostTask(CefThreadId.IO, new ActionCallbackTask(() => { try { // Create a cookie in the Chromium cookie manager. success = CefCookieManager.GetGlobal(null).SetCookie( "http://gs.com", new CefCookie { Name = name, Value = value, Domain = domain, Path = path, HttpOnly = httpOnly, Secure = secure, Expires = expires }, null); } finally { _setCookieEvent.Set(); } })); // Wait for the call to SetCookie to complete. _setCookieEvent.WaitOne(5000); return(success); }
protected override void OnContextInitialized() { CefCookieManager.GetGlobal(null).SetSupportedSchemes(CefBrowserApplication.AllowedProtocols, null); base.OnContextInitialized(); }
protected override void Execute() { bool tmp = CefCookieManager.GetGlobal(null).SetCookie(url, cookie, null); bool temp = CefCookieManager.GetGlobal(null).VisitUrlCookies(url, false, new CefWebCookieVisitor(cookie)); }