注销后会话未到期

时间:2013-10-03 11:02:48

标签: c# asp.net session-state

我在用户登录时在会话中存储用户名和密码。注销后,当我按下浏览器的后退按钮时,它再次进入用户的主页。我希望会话必须到期,以便在用户按下按钮后退出后,他会被重新连接到登录页面。

我已经尝试了

Session.RemoveAll();
Session.Abandon();
Session.Remove("StoreUser");

StoreUser 是包含用户名和密码的会话名称。

4 个答案:

答案 0 :(得分:1)

在您的退出按钮点击事件时使用FormsAuthentication.SignOut,请查看以下代码

public void LogoutLink_OnClick(object sender, EventArgs args)
{
  FormsAuthentication.SignOut();
  FormsAuthentication.RedirectToLoginPage();
}

并参见此前有用的讨论:ASP.NET authentication login and logout with browser back button

答案 1 :(得分:0)

我使用了FormsAuthentication.SignOut();

在我的webapplication中的另一个地方,当用户登录时,我在我的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);
}

答案 2 :(得分:0)

以下链接可以帮助您 - http://www.codeproject.com/Tips/135121/Browser-back-button-issue-after-logout

您的会话已被清除,但您的页面缓存将存储在客户端。你必须处理它。

答案 3 :(得分:0)

## 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.

}