当前位置:编程学习 > C#/ASP.NET >>

asp.net怎么清除cookie

requset.cookie.clear()
这个方法 根本就不行 清不掉啊
答案:public static bool DeleteCookie(string CookieName)

{


System.Web.HttpContext.Current.Response.Cookies.Remove(CookieName);


return true;

}
//当用尝试用上面的方法去清除登录的Cookie时,发现并没有清除我的Cookie,重刷页面时登录状态还在
//这个问题花了不少时间来调试,百般无奈,最后找到了一个方法可以解决

//strPageDomain 主要是应用在当Cookie需要跨域时,用来访问strPageDomain这个域名下的Cookie
HttpCookie MyCo;


if (_strPageDomain != null && _strPageDomain != "")


{



MyCo = HttpContext.Current.Request.Cookies["UserID"];



if (System.Web.HttpContext.Current.Request.ServerVariables.ToString().IndexOf(_strPageDomain) >= 0 && MyCo != null)



{




MyCo.Domain = _strPageDomain;




MyCo.Expires = DateTime.Now.AddHours(-24); //关键是这一句




HttpContext.Current.Response.Cookies.Add(MyCo);




}


}


else


{



MyCo = HttpContext.Current.Request.Cookies["UserID"];



if (MyCo != null)



{




MyCo.Expires = DateTime.Now.AddHours(-48);







HttpContext.Current.Response.Cookies.Add(MyCo);



}



}
设置过期时间为昨天
清空Cookie : Request.Cookie.Remover()

上一个:怎样学好ASP.NET?
下一个:ASP.net是什么

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,