Vijaya
Vijaya

Reputation: 101

Logout functionality

How can I implement logout feature on my page so that user is redirected to a login page and is not allowed to view previous page?

 FormsAuthentication.SignOut(); is it enough for logout.

Upvotes: 2

Views: 1753

Answers (3)

Paulie Waulie
Paulie Waulie

Reputation: 1690

    /// <summary>
    /// Logs the user out of their forms authentication.
    /// </summary>
    public void SignOut()
    {
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }

Upvotes: 3

Win
Win

Reputation: 62260

You also want to remove the session state after SignOut.

FormsAuthentication.SignOut(); 

// Remove all session variables and destroy session
context.Session.RemoveAll();
context.Session.Clear();
context.Session.Abandon();

Upvotes: 2

Geeky Guy
Geeky Guy

Reputation: 9399

Page_Load (object sender, EventArgs e) {
if (!User.IsAuthenticated) {
    Response.Redirect("login.aspx");
}

Also I'd have that in a the master page.

Upvotes: 2

Related Questions