Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fredrik Esseen 610 posts 906 karma points
    Dec 11, 2013 @ 11:01
    Fredrik Esseen
    0

    Check if member is already logged in

    Hi!

    A customer of mine wants to create a website that lets members log in, but since he's going to charge members for creating an account he doesn't want members to be able to log in with the same account if someone is already logged in with the same account.

    Ive looked at user.IsOnline but it seems that all members are online all the time? Is it a bug? Im using v6.1.6. Or are there some other way to check the members?

    List<MembershipUser> onlineUsers = new List<MembershipUser>();
    bool alreadyLoggedIn = false;
    
    foreach (MembershipUser user in Membership.GetAllUsers())
      {
          if (user.IsOnline)
          {
            if (user.UserName.ToLower() == username.ToLower())
                {
            alreadyLoggedIn = true;
            break;
                }
    
              }
    }
            if(alreadyLoggedIn == false)
        {
    
        FormsAuthentication.SetAuthCookie(username, true);
        Response.Redirect(requestedUrl);
        }
        else
        {
        message = "Already logged in";
            showMessage = true;
            showLoginForm = true;
    
        }
    
  • Charles Afford 1163 posts 1709 karma points
    Dec 17, 2013 @ 22:36
    Charles Afford
    0

    Use the Aspnet membership methods

    I cannot remember of the top of my head but there is one on there like

    IsAuthenticated(pass in the member object)

    Charlie :)

Please Sign in or register to post replies

Write your reply to:

Draft