Page view counter

How to logout a user programmatically?

Last post 12-11-2006 7:20 PM by multiplex7777. 8 replies.

Sort Posts:

  • How to logout a user programmatically?

    11-09-2006, 10:53 PM

    Hi everyone,

    Is there a way I can logout a currently-logged-in user programmatically?

    I have a CreateUserWizard. After the user chooses a username and pwd, I need the user to be logged in so that his/her profile information can be saved. But after all his/her profile info is updated in the database, I want to log the user out.

    Thanks in advance for the help. 

  • Re: How to logout a user programmatically?

    11-10-2006, 12:02 AM
    • Loading...
    • aus_nexxus
    • Joined on 11-01-2002, 11:14 PM
    • Australia
    • Posts 1,156
    • Points 8,018
    • TrustedFriends-MVPs

    When a user is logged in there is a FormsAuthentication Cookie set with their current set of roles.  You should just be able to delete the cookie which will effectively log the person out.

     Let me know how you get on.

    Philip Beadle (MVP, MCAD, MCT DotNetNuke Core Team)
  • Re: How to logout a user programmatically?

    11-10-2006, 12:13 AM
    Answer
    • Loading...
    • shados
    • Joined on 07-07-2006, 11:24 PM
    • Posts 2,198
    • Points 12,098
    FormsAuthentication.SignOut() will do it.

    Also consider Session.Abandon() before calling that, to be sure stuff didn't stay :)
  • Re: How to logout a user programmatically?

    11-10-2006, 12:17 AM

    Thanks for your reply.

    CreateUserWizard automatically logs in the user (I guess LoginCreatedUser is implicitly set to true). HOw do I delete the FormsAuthentication cookie?

    Thanks for the help.

  • Re: How to logout a user programmatically?

    11-10-2006, 1:34 AM
    • Loading...
    • shados
    • Joined on 07-07-2006, 11:24 PM
    • Posts 2,198
    • Points 12,098
    What I told you will do exactly that.
  • Re: How to logout a user programmatically?

    11-10-2006, 1:51 AM

    Thanks shados. Your solution worked.

    Sorry, I was writing out my post when you sent your 1st reply. Didn't see it until after I had posted.

  • Re: How to logout a user programmatically?

    11-10-2006, 3:18 AM
    • Loading...
    • shados
    • Joined on 07-07-2006, 11:24 PM
    • Posts 2,198
    • Points 12,098
    Ahh, I see. No problem. Glad it helped :)
  • Re: How to logout a user programmatically?

    12-11-2006, 5:17 PM
    • Loading...
    • jogi
    • Joined on 11-11-2006, 7:12 AM
    • San Francisco, CA
    • Posts 80
    • Points 445

    A better way to do this is to change the LoginCreatedUser Property to false.  Especially if you're using the control for an admin account to create new users in your Web app (Otherwise, you would unexpectedly logout whenever you add users).  Hope that helps.

     
    -jogi

    Filed under:
  • Re: How to logout a user programmatically?

    12-11-2006, 7:20 PM
    THanks Jogi. Actually my intention IS to bump off all the logged in users, as these are the users creating the account, not admin. But I'll probably use your technique when I enable Admin to also add an account.
Page 1 of 1 (9 items)