Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Programmatically get last login time of a user

  Asked By: Justin    Date: Feb 04    Category: Sharepoint    Views: 8907

We have a SP2007 site and I want to generate a report of users with the
time they last logged into the site.

Does anyone know how I get the login time of the user programmatically?

Share: 

 

11 Answers Found

 
Answer #1    Answered By: Alex Davis     Answered On: Feb 04

Do you have access to the WFE IIS logs? Log Parser works well for this kind of
reporting.

 
Answer #2    Answered By: Sylvester Rich     Answered On: Feb 04

I can't understand why Microsoft doesn't record the last login  time for the
user and provides a property for SPUser obeject.

 
Answer #3    Answered By: Jocelyn Scott     Answered On: Feb 04

If the user  account is active directory backed, you can get the last logon
time from the directory.

 
Answer #4    Answered By: Gloria Mendoza     Answered On: Feb 04

While you are correct, in some intranet deployments it might as well be the
same thing. In extranet scenarios, this obviously would not work as the
remote user  store may be not directly accessible or even contain the correct
information.

I think it would be fairly easy to create an http module that links into a
database that stores this information and updates with each page refresh. It
can then be accessible either through a direct db callout or a custom api.
It might even be possible to attach this data to a user property somehow and
insert it directly in the database in which case, all you would need is some
sp object model calls and you're set.

 
Answer #5    Answered By: Harshad Jawalkar     Answered On: Feb 04

Where I work you can't count on the A.D. login  being the same as the last access
to SP. We use A.D. for everything else, too, like folder access on the SAN and
logging in to your machine, etc...

Maybe I don't understand your solution's angle on the issue?

 
Answer #6    Answered By: Gyan Nene     Answered On: Feb 04

SharePoint relies on external sources for authentication, i.e. checking your
username and password. However, for user  information, sharepoint actually
stores this in a database. In the other thread about email addresses I
mentioned the timer jobs that run to import this information from the
directory to sharepoint. By default, it only syncs once, at the user's
initial logon. All user attributes are then copied to the sharepoint config
db as an SPUser object. These SPUsers can then have additional information
attached to them, such as permissions, photos, and a handful of other stuff.
This info is explained in detail over at bamboo solution's blogs. I'm not
100% positive, but I think this feature is only available on MOSS
installation, not the freebie SPS. The SPUser object can easily be
accessed programmatically  from a page or webpart.

So to summarize what I was referring to:
Option 1) create something to inserts this data into an SPUser object
(either through the OM or a direct database call) that runs on every inbound
request from that user and updates the last logon (which would really be the
last request from this user). This information can then be pulled from the
SPUser object model via a custom web part which is insert into the master
page of a site  near the search bar for example.

Option 2) create something to inserts this data into a separate database
call that runs on every inbound request from that user and updates the last
logon (which would really be the last request from this user). This
information can then be pulled from a custom web part or perhaps a data
query part which i insert into the master page of a site near the search bar
for example. The down side to this is that the database credential needs to
be stored somewhere.

Possible scenarios:
When a web part runs and the site is an intranet site using NTLM auth from a
trusted domain, the web part runs AS the user that is viewing the page.
Therefore the web part, if using integrated security, will attempt to
connect to the database AS that user, not as the sharepoint farm account.
(there are ways around this, but I haven't attempted it yet). In this case,
the web part will need a username/password to the database, which would
probably end up in a web.config which should be encrypted.

When a web part runs and the site is an extranet site using ADFS, Forms, or
something else, the web part runs as the anonymous IIS user account.
Therefore the web part, if using integrated security, will attempt to
connect to the database using the anonymous IIS user account, not as the
sharepoint farm account. (there are ways around this, but I haven't
attempted it yet). In this case, the web part will still need a
username/password to the database, which would probably end up in a
web.config which should be encrypted.

So in short, it's a slightly bigger problem to solve for production
usage. Amazingly MOSS 2010 still does not have this feature (at least it's
not in the OM).

Feel free to send me an email directly Kristopher. I'm government as well,
perhaps we can set up some kind of joint activity.

 
Answer #7    Answered By: Narasimha Madivalar     Answered On: Feb 04

Enable Session and track logins in Session On Start and Session On End Events..

 
Answer #8    Answered By: Hiral Daftary     Answered On: Feb 04

What API are you referring to specifically? I do see anything in ASP.NET or
the SharePoint api's that I can attach something for on session start.

 
Answer #9    Answered By: Rosalie Buckner     Answered On: Feb 04

Same way you do it in ASP.net

but in Sharepoint you have to do an additional Application directive

forums.asp.net/p/1105727/2752427.aspx#2752427

bryantlikes.com/...gSharePointUsingGlobalasax.aspx

 
Didn't find what you were looking for? Find more on Programmatically get last login time of a user Or get search suggestion and latest updates.




Tagged: