I just want to add one more thing that you can use, although this is also not accurate as Denis mentioned, there is
IsOnline property on the ASP.NET MembershipUser object but note that this relies on the
LastActivityDate which isn't updated that much as per:
The LastActivityDate for a user is updated to the current date and time by the CreateUser and ValidateUser methods, and can be updated by some overloads of the GetUser method. You can use the UpdateUser method to set the LastActivityDate property to a specific date and time.
The LastActivityDate is used to determine whether a user is online. A user is considered online if the current date and time minus the UserIsOnlineTimeWindow property value is earlier than the LastActivityDate for the user.
In some scenarios we are using a small service method which will update that value and call to that service method is scheduled on client-side so that LastActivityDate can be more accurate.
/// <summary>
/// Updates users online status.
/// </summary>
/// <param name="userIds">User ids.</param>
[WebMethod]
public
void
UpdateUserOnlineStatus(
string
[] userIds)
{
var userId = SecurityUtility.GetUserId();
Task.Factory.StartNew(() => GenericRepository.GetInstance().UpdateLastActivityDate(userId, DateTime.Now));
}
private
void
UpdateLastActivityDate(Guid userId, DateTime date)
{
try
{
AspnetUsersEntity user =
new
AspnetUsersEntity();
user.LastActivityDate = date.ToUniversalTime();
RelationPredicateBucket bucket =
new
RelationPredicateBucket();
bucket.PredicateExpression.Add(AspnetUsersFields.UserId == userId);
UpdateEntitiesDirectly(user, bucket);
}
catch
{ }
}
var
users =
new
Array();
users.push(
'SomeUserId'
);
GenericService.UpdateUserOnlineStatus(users,
function
(result) {
});
Regards