コード例 #1
0
ファイル: Http.cs プロジェクト: 316729240/M5
 public void addCookie(HttpCookieCollection c)
 {
     for (int i = 0; i < c.Count; i++)
     {
         cookies.Remove(c[i].Name);
         cookies.Set(c[i]);
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
 static void ReplaceVisitorIdCookie(HttpCookieCollection responseCookies, string visitorId)
 {
     responseCookies.Remove(NcbtVisitorIdCookieName);
     responseCookies.Add(new HttpCookie(NcbtVisitorIdCookieName, visitorId)
     {
         Expires = DateTime.UtcNow.AddYears(10)
     });
 }
コード例 #5
0
ファイル: source.cs プロジェクト: zhimaqiao51/docs
    private void Page_Load(Object sender, EventArgs e)
    {
        HttpCookieCollection MyCookieCollection = Response.Cookies;

// <Snippet1>
        MyCookieCollection.Remove(MyCookie);

// </Snippet1>
    }
コード例 #6
0
        public void Clear(HttpCookieCollection cookies)
        {
            if (!cookies.AllKeys.Contains(CookieName))
            {
                return;
            }

            cookies.Remove(CookieName);
        }
コード例 #7
0
        private void Set(HttpCookieCollection cookieCollection, HttpCookie cookie)
        {
            if (cookieCollection.AllKeys.Contains(cookie.Name))
            {
                cookieCollection.Remove(cookie.Name);
            }

            cookieCollection.Add(cookie);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
 private void RemoveCookie(HttpCookieCollection cookies)
 {
     try
     {
         cookies.Remove(CookieName);
     }
     catch (Exception ex)
     {
         _logService.Error(string.Format("Error removing cookie {0}", CookieName), ex);
     }
 }
コード例 #10
0
 private static void RemoveCookie(HttpCookieCollection cookies)
 {
     try
     {
         cookies.Remove(CookieName);
     }
     catch (Exception)
     {
         //Logger.Error(string.Format("Error removing cookie {0}", CookieName), ex);
     }
 }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
 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);
     }
 }
コード例 #13
0
        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");
        }
コード例 #14
0
        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();
        }
コード例 #15
0
        /// <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);
        }
コード例 #16
0
ファイル: Roles.cs プロジェクト: prakritidev/mono
		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);
			}
		}
コード例 #17
0
        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);
                }
            }
        }
コード例 #18
0
    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);
        }
    }
コード例 #19
0
        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());
                }
            }
        }
コード例 #20
0
 /// <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);
 }
コード例 #21
0
 private static void updateCookie(HttpCookie cookie, HttpCookieCollection cookies)
 {
     cookies.Remove(cookie.Name);
     cookies.Add(cookie);
 }
コード例 #22
0
 public void Delete(string key)
 {
     _cookies.Remove(key);
 }