退出时清空Cookies的问题
我在登陆页中保存了COOKIES
Response.Cookies[ "TrueName "].Value = sdr[ "TrueName "].ToString();
Response.Cookies[ "TrueName "].Expires = DateTime.Now.AddMinutes(30);
过期时间为30分钟
在退出页的Page_Load事件中
Response.Cookies.Clear();
这样我在其他页还是可以读出Cookies值,怎么回事呢?
后来我又写成下面这样
Response.Cookies[ "TrueName "].Value = " ";
Response.Cookies.Clear();
结果还是一样,在其他页还是可以读出Cookies的值,为什么清空不掉呢?
------解决方案--------------------加入Cookie:
HttpCookie cookie = new HttpCookie( "MyCookie ");
cookie1.Values.Add( "TrueName ",sdr[ "TrueName "].ToString());
Response.Cookies.Add(cookie);
======================================
注销的时候:
HttpCookie cookie = Request.Cookies[ "MyCookie "];
cookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cookie);
------解决方案-------------------- /// <summary>
/// 删除cookie,传值cookiename
/// </summary>
/// <param name= "cookiename "> </param>
public void delcookie(string cookiename)
{
HttpCookie cookie = new HttpCookie( " "+ cookiename + " ", null);
cookie.Expires = DateTime.Now.AddDays(-1);
System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
System.Web.HttpContext.Current.Response.Cookies.Remove( "cookie ");
}