How LogOut is an ASP Membership

protected void Button2_Click(object sender, System.EventArgs e) //logout { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { System.Web.HttpContext.Current.Session.Abandon(); // it isn't logout >_< } } 

how to log out ?: P

+7
source share
2 answers

If you use standard membership providers and forms authentication:

 FormsAuthentication.SignOut(); HttpContext.Current.Session.Abandon(); 

Usually works with pleasure.

Keep in mind that if the user clicks back in their browser, they are likely to see the cached (registered) version.

Change response to comment

I got the impression that FormsAuthentication.Signout :

Removes a forms authentication ticket from the browser.

And that, since the authentication ticket is completely separate from it and is not connected with the session token, if you want to completely clear all user knowledge from the server at this moment, calling Session.Abandon is good. I know that a new session will be created for them in the next page request - I would be interested to see the documentation about the opposite.

+10
source share
 FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage(); 

This should log out and go to the login page.

+2
source share

All Articles