masterfy

 

移除指定Cookie

         /// <summary>
        /// 移除指定Cookie
        /// </summary>
        /// <param name="cookiesName">Cookies名称</param>
        public static void RemoveCookies(string cookiesName)
        {
            //HttpContext.Current.Response.Cookies.Remove(cookiesName);

            //上述方法不能清除。下面的经测试正确。.测试环境:Windows XP SP2,IE6.0

           HttpCookie cookies = HttpContext.Current.Request.Cookies[cookiesName];
           if (cookies != null)
           {
              cookies.Expires = DateTime.Now.AddDays(-1);
              cookies.Values.Clear();
              System.Web.HttpContext.Current.Response.Cookies.Set(cookies);
           }
        }

posted on 2007-12-04 18:03  masterfy  阅读(415)  评论(0编辑  收藏  举报

导航