Try our conversational search powered by Generative AI!

Users latest login

Vote:
 

Hi, is there any way to fetch date and time of the latest login from code? If so how?

#44253
Oct 07, 2010 11:55
Vote:
 

Hi Johan!

You could use something like this:

using System.Web.Security;

MembershipUser currentUser = Membership.GetUser();
DateTime lastLogin = currentUser.LastLoginDate;

/johan

#44259
Oct 07, 2010 15:55
Vote:
 

Thanks for the reply. I received my EPiServer user by using the code provided. However, the LastLoginDate was not set. Why is this? 

#44306
Oct 08, 2010 8:53
Vote:
 

Not all MembershipProvider's "provide" this information. What provider are you using?

/johan

#44308
Oct 08, 2010 9:45
Vote:
 

The users I tried with use the EPiServerCommonMembershipProvider provider. Which one should I use to make this work?

#44312
Oct 08, 2010 10:08
Vote:
 

Uhm, yeah, I think that this provider dont handle the LastLoginDate, it'll always be set to DateTime.MinValue.

You could possibly write your own MembershipProvider and let it derive from EPiServerCommonMembershipProvider, and in an override to GetUser() let it call base.GetUser() and if the flag "userIsOnline" is set to true, simply set the LastLoginDate to DateTime.Now before
returning the MembershipUser

/johan

#44315
Oct 08, 2010 10:32
Vote:
 

ok thanks. I will investigate this since we are building a very large site and the user handling is already implemented. I'm not sure which risks/problems this implementation would convey.

#44316
Oct 08, 2010 10:36
Vote:
 

Apparently there is a table called tblEPiServerCommunityOnlineStatusLog in which you can find login history for users. This could be an option.

#44326
Oct 08, 2010 14:23
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.