ASP.NET Login/Membership - How to logout?

18,773

Solution 1

On logout to completely clear out the logged in user I would use:

Session.Clear()
Session.Abandon()
FormsAuthentication.SignOut()
FormsAuthentication.RedirectToLoginPage()

Solution 2

I'll just accept Ira's answer because my question was wrong.

This is the solution to the Umbraco bug:

Add an onloggedout to the LoginStatus

<asp:LoginStatus ... onloggedout="UmbracoLogout" />

that manually clears the cache

  protected void UmbracoLogout(object sender, EventArgs e)
  {
    Member.RemoveMemberFromCache(Member.CurrentMemberId());
    Member.ClearMemberFromClient(Member.CurrentMemberId());
  }

(from http://our.umbraco.org/projects/website-utilities/nforum/bugs/18405-Cache-problem)

Share:
18,773
Emiel Bruijntjes
Author by

Emiel Bruijntjes

Updated on June 04, 2022

Comments

  • Emiel Bruijntjes
    Emiel Bruijntjes almost 2 years

    I am using the <asp:LoginStatus> control (along with <asp:Login>)

    I login successfully as A.
    Then I logout.
    If I then login as B, the current user is still A.
    (Both <asp:LoginName> and HttpContext.Current.User.Identity.Name are showing A)

    I have to clear the cookies to completely logout.

    Why doesn't the .NET login control log me out properly? Anyone has any idea?

    EDIT: I apologize everyone! This is an Umbraco bug. I forgot I was using UmbracoMembershipProvider