views:

50

answers:

1

I want to find out the last login time for a user in my ASP.NET MVC 1.0 application. I'm using the Membership provider for authentication. Although I'm able to retrieve the last login time using:

public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)
    {

        if (!ValidateLogOn(userName, password))
        {
            return View();
        }

        string lastLogin = Membership.GetUser(userName).LastLoginDate.ToString();

This returns the current time from the column LastLoginDate from aspnet_Membership table. Is there a way to tap into the former login time before the records get updated? Are cookies the only way to do this?

+1  A: 

Try to call the line before you do the ValidateLogOn. The LastLoginDate is updated if Membership.ValidateUser is called, and I suppose you call that in ValidateLogOn. So if you start your LogOn with your current last line then it should give you really the last login date....

apolka
I'm having a similar problem in ASP.NET WebForms. But I'm setting the authentication cookie which makes it rather more difficult- because I believe the user will stay logged in from the point they first create the user for the expiry of the cookie (50 years, apparently?).What I need to do is somehow intercept the 'last activity' date before its updated when the user comes back to the page after their page has expired - or am I missing something?
Ian Grainger