退出登陆清空session和cookie

2次阅读
没有评论

点击退出登陆,跳转到该页,下面是该页的page_load代码

private void Page_Load(object sender, System.EventArgs e)
{
      Session[Constants.Agent_KEY] = null;
   Session[Constants.WebUser_KEY] = null;
   if(Request.Cookies[Constants.Agent_COOKIES]!=null)
   {
    Response.Cookies[Constants.Agent_COOKIES].Expires = DateTime.Now;
    Response.Cookies[Constants.Agent_COOKIES].Value = "";
   }
   if(Request.Cookies[Constants.WebUser_COOKIES]!=null)
   {
    Response.Cookies[Constants.WebUser_COOKIES].Expires = DateTime.Now;
    Response.Cookies[Constants.WebUser_COOKIES].Value = "";
   }
   Response.Redirect("../../index.aspx");//清空后,跳转到您想到的页面
}