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

限于喜欢 提交于 2019-12-11 18:52:55

问题


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. Now i have a problem in logout.

When user pressed "Logout" the link is redirected to "Login.aspx" page. 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..!


回答1:


you can try

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

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



回答2:


Use the following code:

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

FormsAuthentication.RedirectToLoginPage();



回答3:


If you are using MasterPage then in the Code Behind of your MasterPage, you can do this

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

Also do not forget to clear the Session while Logging off.



来源:https://stackoverflow.com/questions/9766804/how-to-kill-the-session-of-user-when-he-loggedout-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!