How to update the last login date if "Remember me"?

When a user registers on my site, the date of visit is indicated in the database (user table). This is handled by the provider (user) membership. However, if the user checks "Remember me?" at the entrance to the system, they (naturally) are not requested to enter the system on subsequent visits. Because the membership provider is not used in this situation, the last database entry date is not updated.

Using forms authentication, how can I guarantee that the last login date is updated with every new visit to the site, and not just with a physical login? Is there any event that I can connect to to achieve this?

I cannot use the session state, since it is completely disabled on the website I am developing (the session module has been deleted).

thanks

+4
source share
2 answers

I assume that you use cookies (I don’t see how “Remember me” will work differently).

When a user logs in, set two cookies, one permanent (if "Remember me" is checked) and one temporary (this session). The second is what you use to authorize the user.

So, on the page where the user should log in, find the session cookie. If found, continue as usual. If not found, find the persistent cookie, if it is found, look at the user, set the login date and set the session cookie. (If a persistent cookie is not found, it simply is not logged in).

+2
source

Assuming you're talking about ASP.NET 2.0 (given the comment of a membership provider).

Wherever you check your cookie, to check whether the user should be autologized, you should call the membership provider GetUser function, which takes a boolean to update the user’s activity date.

In MSDN Docs :

MembershipProvider.GetUser Method

It takes as input a unique user ID and a boolean value indicating whether the LastActivityDate value should be updated for the user to indicate that the user is currently online. The GetUser method returns a MembershipUser object filled with current values ​​from the data source for the specified user. If the username is not found in the data source, the GetUser method returns null (Nothing in Visual Basic).

0
source

All Articles