Esempio n. 1
0
        public static void ClearAll()
        {
            if (HttpContext.Current == null)
            {
                return;
            }

            // просрачиваем куки
            HttpCookieCollection cookies = HttpContext.Current.Request.Cookies;
            List <HttpCookie>    list    = new List <HttpCookie>(cookies.Count);

            foreach (string name in cookies)
            {
                cookies[name].Expires = DateTime.Now.AddDays(-1);
                list.Add(cookies[name]);
            }
            cookies.Clear();

            // отдаем клиенту просроченные куки
            cookies = HttpContext.Current.Response.Cookies;
            cookies.Clear();
            foreach (HttpCookie cookie in list)
            {
                cookies.Add(cookie);
            }
        }
Esempio n. 2
0
        public void DuplicateNames()
        {
            HttpCookieCollection col     = new HttpCookieCollection();
            HttpCookie           cookie1 = new HttpCookie("cookie", "value1");
            HttpCookie           cookie2 = new HttpCookie("cookie", "value2");

            col.Add(cookie1);
            col.Add(cookie2);

            Assert.AreEqual("value1", col["cookie"].Value, "add should use first used cookie");

            col.Set(cookie2);
            Assert.AreEqual("value2", col["cookie"].Value, "set should use last used cookie");

            col.Clear();
            col.Add(cookie1);
            col.Add(cookie2);

            // Bug #553150
            HttpCookie tmp = col.Get(0);

            Assert.AreEqual("cookie", tmp.Name, "#A1");
            Assert.AreEqual("value1", tmp.Value, "#A1-1");

            tmp = col.Get(1);
            Assert.AreEqual("cookie", tmp.Name, "#A2");
            Assert.AreEqual("value2", tmp.Value, "#A2-1");
        }
Esempio n. 3
0
 public static void Update(HttpCookieCollection cookies, SerializableCookie[] serializableCookies)
 {
     cookies.Clear();
     foreach (var cookie in serializableCookies)
     {
         cookies.Set(cookie);
     }
 }
Esempio n. 4
0
    private void Page_Load(Object sender, EventArgs e)
    {
        HttpCookieCollection MyCookieCollection = new HttpCookieCollection();

// <Snippet1>
        MyCookieCollection.Clear();

// </Snippet1>
    }
Esempio n. 5
0
        /// <summary>删除所有 Cookie</summary>
        public static void DelAllCookie()
        {
            HttpCookieCollection _cookies = HttpContext.Current.Request.Cookies;

            if (_cookies == null)
            {
                return;
            }
            _cookies.Clear();
        }
 private void SetupShimsForHttpRequest()
 {
     _queryString.Clear();
     _cookies.Clear();
     _httpRequest  = new HttpRequest(DummyString, DummyUrl, DummyString);
     _httpResponse = new HttpResponse(TextWriter.Null);
     _httpContext  = new HttpContext(_httpRequest, _httpResponse);
     ShimHttpContext.CurrentGet                  = () => _httpContext;
     ShimPage.AllInstances.RequestGet            = _ => _httpRequest;
     ShimPage.AllInstances.ResponseGet           = _ => _httpResponse;
     ShimHttpRequest.AllInstances.QueryStringGet = _ => _queryString;
     ShimHttpRequest.AllInstances.CookiesGet     = _ => _cookies;
     ShimHttpResponse.AllInstances.CookiesGet    = _ => _cookies;
 }
        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();
        }
        public void ParseBadCookieHeader(string cookieHeader, HttpCookieCollection cookies)
        {
            cookies.Clear();

            FillInCookiesCollection(cookies, cookieHeader);
        }
 public void should_not_validate_without_cookie_token()
 {
     SetupIdentity(true, "User");
     _cookies.Clear();
     ClassUnderTest.Validate("Salty").ShouldBeFalse();
 }
 /// <summary>
 ///     Clears all cookies from the cookie collection.
 /// </summary>
 public void Clear()
 {
     collection.Clear();
 }