public static HttpCookie SetCookie(this HttpResponse response, string name, string value, int expiryDays) { var cookie = response.Cookies[name]; if (cookie != null) response.Cookies.Remove(name); cookie = new HttpCookie(name, value); cookie.Path = "/"; if (expiryDays > 0) cookie.Expires = DateTime.Now.AddDays(expiryDays); response.Cookies.Add(cookie); return cookie; } public static void DeleteCookie(this HttpResponse response, string name, HttpRequest request) { var c = request.Cookies[name]; request.Cookies.Remove(name); if (c != null) { c.Expires = DateTime.Now.AddDays(-10); c.Value = null; response.SetCookie(c); } }