简体   繁体   English

如何在ASP.NET中使用LoggedOut时终止用户会话

[英]How to kill the Session of User when he LoggedOut in ASP.NET

I have a asp.net web application login page which has buil-in Authentication of asp.net and login.aspx page created by Login control of asp.net. 我有一个asp.net Web应用程序登录页面,它具有asp.net的登录身份验证和asp.net的登录控件创建的login.aspx页面。 Now i have a problem in logout. 现在我在注销时遇到了问题。

When user pressed "Logout" the link is redirected to "Login.aspx" page. 当用户按下“注销”时,链接将重定向到“Login.aspx”页面。 But, when the user press "Back" button from the browser the user "Login"to the page to the application which i want to avoid and it must ask to enter Login Credentials. 但是,当用户从浏览器按“返回”按钮时,用户“登录”到我要避免的应用程序页面,并且必须要求输入登录凭据。

Help Appreciated..! 帮助感谢...! Thanks in Advace..! 谢谢Advace ..!

you can try 你可以试试

   protected void btnLogout_Click(object sender, EventArgs e)
    {
        Session.RemoveAll();
        Session.Abandon();

        Response.Redirect("LoginPage.aspx");
    }

If you are using MasterPage then in the Code Behind of your MasterPage, you can do this 如果您使用的是MasterPage那么在您的MasterPage的Code Behind中,您可以执行此操作

Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
Response.Expires = -1500;
Response.CacheControl = "no-cache";

Also do not forget to clear the Session while Logging off. 另外,请不要忘记在注销时清除会话。

Use the following code: 使用以下代码:

Session.RemoveAll();
 FormsAuthentication.SignOut(); 

FormsAuthentication.RedirectToLoginPage();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当同一用户ID尝试登录多台设备时,如何杀死另一台设备上的会话? Asp.net身份 - When the same user ID is trying to log in on multiple devices, how do I kill the session on the other device? Asp.net Identity 如何终止会话或会话 ID (ASP.NET/C#) - How to Kill A Session or Session ID (ASP.NET/C#) 当用户取消选中Asp.net中的checkboxlist控件时如何响应 - How to response the user when he uncheck the checkboxlist control in Asp.net 当管理员更改asp.net时如何杀死登录用户会话? - How to kill session of login users when admin changes right asp.net? ASP.NET按ID删除会话 - ASP.NET Kill Session By Id 如何在asp.net中维护用户会话? - How to maintain User Session in asp.net? 注销后,如何在ASP.NET MVC3中单击浏览器的后退按钮时将用户重定向到登录页面 - After logout,how to redirect user to login page when he/she will click back button of browser in ASP.NET MVC3 Asp.NET |获取用户在打开网站时的Ip \\单击按钮 - Asp.NET|Get Ip Of a user when he open the site\click on a button 如何在asp.net mvc 3登录后将用户重定向回到他所在的位置 - How to redirect a user back to where he was after login in asp.net mvc 3 如何在ASP.NET核心确认用户email后才改变用户的Email - How to change user's Email in ASP.NET core only after he confirmed his email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM