一、在退出时移除Session,首先在登录时要记录登录信息
Session["id"] = user.id.ToString(); Session["name"] = user.name.ToString(); Session["pwd"] = user.password.ToString(); Session["time"] = user.LoginTime.ToString(); Session["limit"] = user.limits.ToString();
二、当点击退出系统时,移除Session,清除缓存
public void Clear(object sender, EventArgs e) { Session["id"] = null; Session["name"] = null; Session["pwd"] = null; Session["time"] = null; Session["limit"] = null; ClearClientPageCache(); Response.Redirect("~/Login.html"); } public void ClearClientPageCache() { //清除浏览器缓存 Response.Buffer = true; Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); Response.Cache.SetExpires(DateTime.Now.AddDays(-1)); Response.Expires = 0; Response.CacheControl = "no-cache"; Response.Cache.SetNoStore(); }
三、
<a target="_self" runat="server" onserverclick ="Clear" >退出</a>