日期:2014-05-18  浏览次数:20466 次

清除COOKIE的一个怪现象
以下是写COOKIE代码
HttpCookie   hc   =   new   HttpCookie( "_user ");
hc.Domain   =   ".com.cn ";
hc.Expires   =   DateTime.Now.AddMonths(1);
hc.Value   =   cookie;
Response.Cookies.Add(hc);

以下是清COOKIE的代码
int   i,   limit;
HttpCookie   cookieName;
limit   =   Request.Cookies.Count;
for   (i   =   0;   i   <   limit;   i++)
{
        cookieName   =   Request.Cookies[i];
        cookieName.Values.Clear();
        cookieName.Values.Remove( " ");
        cookieName.Value   =   " ";
        cookieName.Domain   =   ".com.cn ";
        cookieName.Expires   =   DateTime.Now.AddDays(-7);
        cookieName.Value   =   " ";
        Response.Cookies.Add(cookieName);
        Response.Cookies.Set(cookieName);
}
Response.Cookies.Remove( "_user ");

可是为什么_user这个COOKIE就是清不掉呢,连时间和值都没有变.这个问题弄了一下,

问了三四个群,居然没一个回消息,不知道搞这些群用来干什么.只好到这里来找高手了.

------解决方案--------------------
Response.Cookies.Clear();
Response.Cookies[ "_user "].Value=null;

还有就是设置过期时间

------解决方案--------------------
cookieName.Values.Remove( " ");
改为
cookieName.Values.Remove(i);括号里面的参数是int类型的