public void addCookie(HttpCookieCollection c) { for (int i = 0; i < c.Count; i++) { cookies.Remove(c[i].Name); cookies.Set(c[i]); } }
private static void SetCookie(HttpCookie cookie) { HttpCookieCollection cookies = HttpContext.Current.Response.Cookies; cookies.Remove(cookie.Name); // Doesn't delete from the client, but replacing it so it is unimportant. cookies.Add(cookie); }
public static void SignOut() { Initialize(); HttpContext context = HttpContext.Current; if (context == null) { throw new HttpException("Context is null!"); } HttpResponse response = context.Response; if (response == null) { throw new HttpException("Response is null!"); } HttpCookieCollection cc = response.Cookies; cc.Remove(cookieName); HttpCookie expiration_cookie = new HttpCookie(cookieName, String.Empty); expiration_cookie.Expires = new DateTime(1999, 10, 12); expiration_cookie.Path = cookiePath; if (!String.IsNullOrEmpty(cookie_domain)) { expiration_cookie.Domain = cookie_domain; } cc.Add(expiration_cookie); Roles.DeleteCookie(); }
static void ReplaceVisitorIdCookie(HttpCookieCollection responseCookies, string visitorId) { responseCookies.Remove(NcbtVisitorIdCookieName); responseCookies.Add(new HttpCookie(NcbtVisitorIdCookieName, visitorId) { Expires = DateTime.UtcNow.AddYears(10) }); }
private void Page_Load(Object sender, EventArgs e) { HttpCookieCollection MyCookieCollection = Response.Cookies; // <Snippet1> MyCookieCollection.Remove(MyCookie); // </Snippet1> }
public void Clear(HttpCookieCollection cookies) { if (!cookies.AllKeys.Contains(CookieName)) { return; } cookies.Remove(CookieName); }
private void Set(HttpCookieCollection cookieCollection, HttpCookie cookie) { if (cookieCollection.AllKeys.Contains(cookie.Name)) { cookieCollection.Remove(cookie.Name); } cookieCollection.Add(cookie); }
public static void SetAnonymousUser(this HttpCookieCollection cookies, UserAnonymous user) { HttpCookie cookie = new HttpCookie(anonymousUserCookieName, new UserCookieProxy(user).ToJson()); cookie.Expires = DateTime.Now.AddDays(14); cookies.Remove(anonymousUserCookieName); cookies.Add(cookie); }
private void RemoveCookie(HttpCookieCollection cookies) { try { cookies.Remove(CookieName); } catch (Exception ex) { _logService.Error(string.Format("Error removing cookie {0}", CookieName), ex); } }
private static void RemoveCookie(HttpCookieCollection cookies) { try { cookies.Remove(CookieName); } catch (Exception) { //Logger.Error(string.Format("Error removing cookie {0}", CookieName), ex); } }
private void UnsetAuthorizationCookie(HttpResponseBase httpresponsebase, HttpCookieCollection cookiecollection) { HttpCookie authCookie = cookiecollection[FormsAuthentication.FormsCookieName]; if (authCookie != null) { cookiecollection.Remove(FormsAuthentication.FormsCookieName); authCookie.Expires = DateTime.Now.AddDays(-10); authCookie.Value = null; httpresponsebase.SetCookie(authCookie); } HttpCookie userCookie = cookiecollection["userCookie"]; if (userCookie != null) { cookiecollection.Remove("userCookie"); userCookie.Expires = DateTime.Now.AddDays(-10); userCookie.Value = null; httpresponsebase.SetCookie(userCookie); } }
public static void Delete <T>(this HttpCookieCollection cookie, T key) { if (Exists(cookie, key)) { var httpCookie = new HttpCookie(key.ToString()) { Expires = DateTime.Now.AddDays(-1) }; cookie.Remove(key.ToString()); cookie.Add(httpCookie); } }
public void TestCollection() { HttpCookieCollection col = new HttpCookieCollection(); HttpCookie cookie = new HttpCookie("cookie", "value"); col.Add(cookie); Assert.AreEqual("cookie", col["cookie"].Name, "Name is the key"); col.Remove(cookie.Name); Assert.IsNull(col["cookie"], "removal using name"); }
public void Deny_Unrestricted() { HttpCookieCollection jar = new HttpCookieCollection(); jar.Add(biscuit); jar.CopyTo(new object[1], 0); Assert.IsNull(jar.GetKey(0), "GetKey"); jar.Remove("chocolat"); jar.Set(biscuit); Assert.IsNotNull(jar.Get(0), "Get(int)"); Assert.IsNull(jar.Get("chocolat"), "Get(string)"); Assert.IsNotNull(jar[0], "this[int]"); Assert.IsNull(jar["chocolat"], "this[string]"); Assert.AreEqual(1, jar.AllKeys.Length, "AllKeys"); jar.Clear(); }
/// <summary> /// Use AppSetting COOKIE_TIME /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cookie"></param> /// <param name="key"></param> /// <param name="value"></param> /// <param name="cookieTime"></param> public static void Set <T>(this HttpCookieCollection cookie, T key, object value, int?cookieTime = null) { if (value == null) { value = string.Empty; } var httpCookie = new HttpCookie(key.ToString()) { Value = value.ToString(), Expires = DateTime.Now.AddHours(cookieTime ?? CookieTime), HttpOnly = true }; cookie.Remove(key.ToString()); cookie.Add(httpCookie); }
public static void DeleteCookie () { if (CacheRolesInCookie) { HttpContext context = HttpContext.Current; if (context == null) throw new HttpException ("Context is null."); HttpResponse response = context.Response; if (response == null) throw new HttpException ("Response is null."); HttpCookieCollection cc = response.Cookies; cc.Remove (CookieName); HttpCookie expiration_cookie = new HttpCookie (CookieName, ""); expiration_cookie.Expires = new DateTime (1999, 10, 12); expiration_cookie.Path = CookiePath; cc.Add (expiration_cookie); } }
private void AddAnyNewCookiesToCookieCollection() { if (LastRequestData.Response == null) { return; } var lastResponseCookies = LastRequestData.Response.Cookies; foreach (string cookieName in lastResponseCookies) { var cookie = lastResponseCookies[cookieName]; if (Cookies[cookieName] != null) { Cookies.Remove(cookieName); } if (cookie != null && (cookie.Expires == default(DateTime) || cookie.Expires > DateTime.Now)) { Cookies.Add(cookie); } } }
protected override WebResponse GetWebResponse(WebRequest request) { try { var r = base.GetWebResponse(request); if (r is HttpWebResponse) { ResponseUri = (r as HttpWebResponse).ResponseUri; } for (int i = 0; i < (r as HttpWebResponse).Cookies.Count; i++) { Cookie c = (r as HttpWebResponse).Cookies[i]; if (!c.Expired) { cookies.Remove(c.Name); HttpCookie c2 = new HttpCookie(c.Name, c.Value); c2.Expires = c.Expires; c2.Path = c.Path; c2.Domain = c.Domain; c2.HttpOnly = c.HttpOnly; cookies.Set(c2); this._cookieContainer.Add(c); } //this._cookieContainer.Add((r as HttpWebResponse).Cookies[i]); } // this._cookieContainer.Add((r as HttpWebResponse).Cookies); return(r); } catch { return(null); } }
public object this[object key] { get { HttpCookie cookie = null; if (key is int) { cookie = _cookiecollection[(int)key]; } else { cookie = _cookiecollection[(string)key]; } if (cookie == null) { return(""); } if (_request) { return(new AspReadCookie(cookie)); } else { return(new AspWriteCookie(cookie)); } } set { if (value == null || (value is string && string.IsNullOrEmpty((string)value))) { _cookiecollection.Remove(key.ToString()); } } }
/// <summary> /// Removes the cookie with the specified name from the collection. /// </summary> /// <param name="name">The name of the cookie to remove from the collection. </param> public void Remove(string name) { collection.Remove(name); }
private static void updateCookie(HttpCookie cookie, HttpCookieCollection cookies) { cookies.Remove(cookie.Name); cookies.Add(cookie); }
public void Delete(string key) { _cookies.Remove(key); }