注销后会话未过期
本文关键字:过期 会话 注销 | 更新日期: 2023-09-27 18:33:39
用户登录时,我在会话中存储用户名和密码。注销后,当我按浏览器的"返回"按钮时,它会再次转到用户的主页。我希望会话必须过期,以便在用户按后退按钮注销后,他将重新进入登录页面。
我已经试过了
Session.RemoveAll();
Session.Abandon();
Session.Remove("StoreUser");
存储用户是包含用户名和密码的会话的名称。
使用 FormsAuthentication.SignOut 当您的注销按钮单击事件时,请查看下面的代码
public void LogoutLink_OnClick(object sender, EventArgs args)
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}
并查看之前有用的讨论:ASP.NET 身份验证登录和使用浏览器后退按钮注销
我用了FormsAuthentication.SignOut();
在我的 Web 应用程序的其他地方,当用户登录时,我的 WebForm 上有这个:
<asp:LoginStatus ID="LoginStatus1" LogoutImageUrl="~/Img/Logout.png"
BackColor="Transparent" runat="server" onloggingout="LoginStatus1_LoggingOut" />
这在后面的代码中:
protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
{
MembershipUser u = Membership.GetUser(HttpContext.Current.User.Identity.Name);
u.LastActivityDate = DateTime.Now.AddMinutes(-Membership.UserIsOnlineTimeWindow);
Membership.UpdateUser(u);
}
以下链接可以帮助您 -http://www.codeproject.com/Tips/135121/Browser-back-button-issue-after-logout
您的会话正在被清除,但页面的缓存被存储在客户端。你必须处理这个问题。
## IN Global.asax file you have to clear all the session in Session_end event ##
clear all the session in this event.
protected void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}