Page view counter

problems with Membership.isOnline()

Last post 02-26-2008 7:18 PM by acidcool524. 17 replies.

Sort Posts:

  • problems with Membership.isOnline()

    12-02-2005, 11:39 AM
    • Loading...
    • subgurim
    • Joined on 11-18-2004, 1:42 PM
    • Posts 187
    • Points 868
    Hi, I'm making a forum, and in the posts I want to show some profile characteristcs and show if the user is online.

    The problem is that if I take the user profile of any user, the membership property "LastActivityDate" is updated, and the "IsOnline" returns true when this user is no really online.
    How can I solve this?

    For better information, I do something like this:

            MembershipUser miembro = Membership.GetUser(usuario, false);
            if (miembro != null)
            {
                ProfileCommon profile = Profile.GetProfile(usuario);
          
                sb.Append(profile.example);         

                if (miembro.IsOnline)
                {
                    sb.Append("Está online!!");
                } 
            }

    The Membership.GetNumberOfUsersOnline property also turns a bad value
    I think that this could be solved, isn't it?
    if not, how do (for example) this website give some user profile properties and at the same time give the total number of users online?

    Thanks in advance.
    subgurim.net: blog de ASP.NET 2.0 con C# en castellano
    es-asp.net: el portal de ASP.NET en castellano
  • Re: problems with Membership.isOnline()

    12-03-2005, 5:39 AM
    • Loading...
    • Xanderno
    • Joined on 06-17-2002, 3:24 PM
    • Plano, TX
    • Posts 1,181
    • Points 5,962
    Well, what do you mean by "not really online."?  Do you mean you closed the browser window that that user was logged into, and refeshed another browser window?

    If that's the case, then yes, I'd say that's probably the expected behaviour.  Remember, HTTP is stateless, meaning there's no persistant connection between the server and the client, so there's no such thing as guaranteed notification when a client "leaves" your site.  Once the server has responded to a request, it's over and done with, and that connection is gone.  So, the online status is going to be more of an approximate value akin to active sessions than an actual specific count of connected clients. 

    Now, if you mean that you're seeing a user that hasn't been logged-in in two weeks showing up as online, I'd say that would be a different issue.
  • Re: problems with Membership.isOnline()

    12-08-2005, 1:09 PM
    • Loading...
    • markberr
    • Joined on 07-28-2003, 11:13 AM
    • Microsoft
    • Posts 205
    • Points 1,014
    • AspNetTeam

    For Membership, we say a user is on-line if the last date of activity falls within a configurable "online window".  As Xanderno points out, it's impossible to truly determine if a user is on-line.  At best, you can guess based on activity.

    Thanks,
    Mark

    This posting is provided "AS IS" with no warranties, and confers no rights.

     

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: problems with Membership.isOnline()

    12-08-2005, 6:34 PM
    • Loading...
    • subgurim
    • Joined on 11-18-2004, 1:42 PM
    • Posts 187
    • Points 868
    Xanderno: It's the second issue: a user not logged in two weeks is considered online. I understand the mechanism of http ;) Thanks! Markberr: Yes, that's correct and I know it, the problem is that if I take programatically the profile of a user (ProfileCommon profile = Profile.GetProfile(usuario);), this "last date of activity" is automatically updated. This is the reason that makes that a user logged a long time ago is considered online... and I think it have no sense!! Is there other solution??? Am I correct?? Thanks in advance
    subgurim.net: blog de ASP.NET 2.0 con C# en castellano
    es-asp.net: el portal de ASP.NET en castellano
  • Re: problems with Membership.isOnline()

    12-12-2005, 7:29 PM
    • Loading...
    • markberr
    • Joined on 07-28-2003, 11:13 AM
    • Microsoft
    • Posts 205
    • Points 1,014
    • AspNetTeam

    The behavior you're seeing is expected.  When you lookup up the profile for a user, we update that user's last activity date (LAD) which affects their "online" status for Membership. 

    At some level, we have to make a decision on whether or not an operation is indicative of "user activity".  Looking up a user's profile data just happends to be one of those cases, but I can see that in an administrative environment where you're just pulling up the data, this doesn't make sense.  Except for an explosion in the number of API's, it would be nice to have overloads that allow you to skip updating a user's LAD.  We have such an overload for Membership.GetUser(...). 

    I'll start an internal thread with the team to see if we should overload some of the API's in the next release.

    Thanks,
    Mark

    This posting is provided "AS IS" with no warranties, and confers no rights.

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: problems with Membership.isOnline()

    12-13-2005, 5:57 AM
    • Loading...
    • subgurim
    • Joined on 11-18-2004, 1:42 PM
    • Posts 187
    • Points 868
    yes markberr i was thinkning exactly the same.
    I've seen that there is the overload you said with Membership.GetUser(...), and it will make sense the same one for Profile.GetProfile(...)

    Thanks for your attention
    subgurim.net: blog de ASP.NET 2.0 con C# en castellano
    es-asp.net: el portal de ASP.NET en castellano
  • Re: problems with Membership.isOnline()

    12-13-2005, 8:59 AM
    • Loading...
    • subgurim
    • Joined on 11-18-2004, 1:42 PM
    • Posts 187
    • Points 868
    Another related thing... I don't know if this is the correct side to say this, but I think that with an easy AJAX function would be relatively easy to know if the user is really online: assing an AJAX-Javascript function that polls to the server every onlineTimeWindow minutes.

    The bandwidth needed would be xtremelely little
    subgurim.net: blog de ASP.NET 2.0 con C# en castellano
    es-asp.net: el portal de ASP.NET en castellano
  • Re: problems with Membership.isOnline()

    12-13-2005, 11:49 AM
    • Loading...
    • markberr
    • Joined on 07-28-2003, 11:13 AM
    • Microsoft
    • Posts 205
    • Points 1,014
    • AspNetTeam

    Thanks for bringing up the issue.  We'll be reviewing this API and possibly all API's which update a user's Last Activity Date in a future release.

    Mark

    This posting is provided "AS IS" with no warranties, and confers no rights.

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: problems with Membership.isOnline()

    02-25-2006, 5:34 PM
    • Loading...
    • dengerous
    • Joined on 02-11-2006, 12:39 PM
    • Posts 11
    • Points 40

    I have another problem : after running FormsAuthentication.SignOut()  I see that IsOnline for this member is still true. Why is that and how can I solve it?

  • Re: problems with Membership.isOnline()

    07-17-2006, 9:37 AM
    • Loading...
    • Pekestoemp
    • Joined on 07-17-2006, 1:31 PM
    • Posts 1
    • Points 5

    Hello,

    I'm pretty new in this forum...

    I think that it might be a good work-around, just after you have used the getprofile/save etc to save a profile to use the Getuser, to change the LAD = lastlogindate and to save this into the membershipuser...

    This really avoids to have the incorrect isOnline value.

    Hope this helps...

    Please feel free to let us know :-)

    Regards

    Pekestoemp

  • Re: problems with Membership.isOnline()

    07-20-2006, 6:06 AM
    • Loading...
    • subgurim
    • Joined on 11-18-2004, 1:42 PM
    • Posts 187
    • Points 868
    Hello Pekestoemp,

    Yes, finally it has been solved in this way Big Smile
    subgurim.net: blog de ASP.NET 2.0 con C# en castellano
    es-asp.net: el portal de ASP.NET en castellano
  • Re: problems with Membership.isOnline()

    12-01-2006, 2:51 PM
    • Loading...
    • balam
    • Joined on 11-13-2006, 1:00 AM
    • Posts 14
    • Points 62

    A little more detail on the fix identified above

    A common scenario is to display read only user, profile, and role information in a grid to and administrator.  
    Read only access to role information causes the LastActivityDate to be revised.  

    sample code
    DataTable dt;
    DataRow dr;

    foreach (System.Web.Security.MembershipUser _User in _Users)
    {
        dr = dt.NewRow();
        dr[0] = _User.UserName;
        dr[1] = _User.IsOnline;
        dr[3] = _User.Email;
        //  save UserLastActivityDate so it can be reassigned later
       
    DateTime UserLastActivityDate = _User.LastActivityDate;
        dr[4] = UserLastActivityDate;
        // !!! GetProfile alone does NOT cause an update to LastActivityDate
        ProfileCommon _profile = Profile.GetProfile(_User.UserName);
        //  !!! accessing profile property is what causes and update to LastActivityDate
       
    dr[5] = _profile.FirstName;
        dr[6] = _profile.LastName;
        // need to reset the UserLastActivityDate that has just been updated by above two lines
        _User.LastActivityDate = UserLastActivityDate;
       
    Membership.UpdateUser(_User);
        //  also display role information in the Grid
        dr[7] =
    Roles.IsUserInRole(_User.UserName, "Admin");
        dr[8] =
    Roles.IsUserInRole(_User.UserName, "Employee");
       
    dt.Rows.Add(dr);
    }
    GridViewUsers.DataSource = dt;
    GridViewUsers.DataBind();

    This workaround is wateful of CPU and IO. 
    Microsoft we need an overloaded GetProfile like GetUser.

     

  • Re: problems with Membership.isOnline()

    12-01-2006, 2:51 PM
    • Loading...
    • balam
    • Joined on 11-13-2006, 1:00 AM
    • Posts 14
    • Points 62

    A little more detail on the fix identified above

    A common scenario is to display read only user, profile, and role information in a grid to and administrator.  
    Read only access to role information causes the LastActivityDate to be revised.  

    sample code
    DataTable dt;
    DataRow dr;

    foreach (System.Web.Security.MembershipUser _User in _Users)
    {
        dr = dt.NewRow();
        dr[0] = _User.UserName;
        dr[1] = _User.IsOnline;
        dr[3] = _User.Email;
        //  save UserLastActivityDate so it can be reassigned later
       
    DateTime UserLastActivityDate = _User.LastActivityDate;
        dr[4] = UserLastActivityDate;
        // !!! GetProfile alone does NOT cause an update to LastActivityDate
        ProfileCommon _profile = Profile.GetProfile(_User.UserName);
        //  !!! accessing profile property is what causes and update to LastActivityDate
       
    dr[5] = _profile.FirstName;
        dr[6] = _profile.LastName;
        // need to reset the UserLastActivityDate that has just been updated by above two lines
        _User.LastActivityDate = UserLastActivityDate;
       
    Membership.UpdateUser(_User);
        //  also display role information in the Grid
        dr[7] =
    Roles.IsUserInRole(_User.UserName, "Admin");
        dr[8] =
    Roles.IsUserInRole(_User.UserName, "Employee");
       
    dt.Rows.Add(dr);
    }
    GridViewUsers.DataSource = dt;
    GridViewUsers.DataBind();

    This workaround is wateful of CPU and IO. 
    Microsoft we need an overloaded GetProfile like GetUser.

     

  • Re: problems with Membership.isOnline()

    10-08-2007, 6:07 PM
    • Loading...
    • snsprint
    • Joined on 04-19-2005, 8:41 PM
    • Posts 12
    • Points 27

    I just spent about 4 hours today trying to figure this one out!

    What had me totally confused was that only some of my user's LastActivityDate fields were being updated when their profile properties were accessed, while others did not change.  I discovered that it is not just the "accessing" of the profile property that causes LastActivityDate to change (as stated above), but rather the accessing of a profile property that contains data. For instance I have a boolean profile property called "SendMeEmail".  If the property is not set the user's activity date was not changing when the profile property was read, but if the field was "true" then the activity date was updated. This may seem like an insignificant point, but it created what appeared to be inconsistent and confusing behavior.

    Oddly enough the Profile.Save() method does not cause the LastActivityDate to change, so at least we don't have to waste additional SQL cycles when the profile is saved.

    Thanks for your explanation and solution above!

  • Re: problems with Membership.isOnline()

    10-12-2007, 11:20 AM
    • Loading...
    • hejahv
    • Joined on 03-21-2007, 11:56 AM
    • Posts 20
    • Points 4

    Pekestoemp or any one else.
    Can you show by code how you mean?

Page 1 of 2 (18 items) 1 2 Next >