Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to LogOut in ASP membership

Tags:

.net

asp.net

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 logout ? :P

like image 759
cnd Avatar asked Mar 03 '10 08:03

cnd


2 Answers

If you're using the standard membership providers and forms authentication:

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

Usually works a treat.

Be aware that if the user presses back in their browser, they will probably see the cached (logged in) version.

Edit to respond to comment

I was under the impression that FormsAuthentication.Signout:

Removes the forms-authentication ticket from the browser.

And that as the authentication ticket is completely separate from, and unrelated to the session token, if you want to completely clear all knowledge of the user from the server at that point, calling Session.Abandon is a good thing to do. I'm aware that a new session will be created for them on the next page request - I'd be interested to see documentation to the contrary.

like image 113
Zhaph - Ben Duguid Avatar answered Oct 31 '22 23:10

Zhaph - Ben Duguid


FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();

This should log-off the user and take him to Login page.

like image 30
this. __curious_geek Avatar answered Oct 31 '22 23:10

this. __curious_geek