1

When a user sets the option (remember me) and closes the browser and then opens the site again he does not appear listed with the on-line members.

How can I set a user to on-line after the user reopens the site again?

I am using this code Membership.GetNumberOfUsersOnline(); but it returns 0 on-line

Rabee Alrabee
  • 95
  • 1
  • 7
  • 2
    Have you set the [userIsOnlineTimeWindow property](http://msdn.microsoft.com/en-us/library/system.web.security.membership.userisonlinetimewindow.aspx) in your web.config? – Josh Darnell Aug 06 '13 at 18:38
  • @jadarnel27 - doubt they want the user to be shown as online when they aren't for weeks at a time. – Erik Funkenbusch Aug 06 '13 at 18:41
  • 1
    @MystereMan I wasn't recommending they set it to a large number. I was just wondering if they had it set to a very small number by mistake (like 1). In which case, I could see them ending up with 0 users online pretty frequently. And the OP might not know that this setting factors in to the results of the call to GetNumberOfUsersOnline(). Are you picking up what I'm putting down, yo? – Josh Darnell Aug 06 '13 at 18:51

2 Answers2

1

If by "sets the option" you mean sets the "remember me" flag. The reason for this is that this just sets a persistent cookie on the users computer. They are not "logged in" again afterwards. Thus, the Membership login never occurs again.

You need to perform some membership activity that has a "userIsOnline" flag, such as calling Membership.GetUser(username, true) to set the userIsOnline.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
0

As an alternative, if you want to track users online, you could look at SignalR, see some tutorials here.

There's a post with a similar question here SignalR for tracking online users and chat.

and here signalR tracking connected users

Community
  • 1
  • 1
Christian Phillips
  • 18,399
  • 8
  • 53
  • 82