views:

1775

answers:

2

Hi,

how could I determine the last login date/time of a user on a MOSS 2007 web application? Till now I didn't find this information within the object model.

I've already thought about requesting the lastLogonTimeStamp form the AD/LDAP but this will be very imprecise.

Another idea would be to write some code to store the login date/time in the user information list whenever a user logs in. But till now I'm not really sure how to do this.

So, does someone know a better solution?

UPDATE

After doing some tests and more thinking about my problem, I realized that in fact I don't need the timestamp of the last login but the timestamp of the last logout respectively of the end of the last session.

As there is now way to get the timestamp of the last login via the object model I can imagine that there is also no way to get the end date and time of the last session.

So how could I get this information?

+2  A: 

Surprisingly there doesn't seem to be a way to get this information using the SharePoint API. However you could retrieve this information from the IIS logs. I think that doing it this way would be more precise than getting it from AD, because a user can login into a system without ever visiting SharePoint.

Another approach would be to use SharePoint auditing. As far as I know there isn't a specific login audit event, but you could audit when a user reads the SharePoint welcome page. Using SPAuditQuery you can retrieve some details.

LeonZandman
The approach with the auditing function sounds great, but it might be a little bit over the top to turn auditing on only to get the login date and time. But I will give it a try.
Flo
+2  A: 
  1. Extend the User Information List with LastSessionID, LastSessionTime
  2. Add a little webcontrol to your master. This webcontrol updates User Information List if the LastSessionID differs. And adds the time.
  3. Ofcourse on Site Collection RootWeb.
Hans