如果“记住我",如何更新上次登录日期放? [英] How to update last login date if "Remember Me" set?

查看:55
本文介绍了如果“记住我",如何更新上次登录日期放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户登录到我的网站时,访问的日期会标记在数据库中(用户表).这是由(自定义)成员资格提供程序处理的.但是,如果用户选中记住我了吗?"选项登录时,(自然)不会提示他们在以后的访问中登录.由于在这种情况下不使用成员资格提供程序,因此上次登录日期不会在数据库中更新.

When a user logs in to my site, the date of the visit is stamped in the database (User table). This is handled by the (custom) membership provider. However, if the user checks the "Remember me?" option when logging in, they are (naturally) not prompted to log in on subsequent visits. As the membership provider is not employed in this situation, the last login date is not updated in the database.

使用表单身份验证,如何确保每次新访问该网站时都更新其上次登录日期,而不是在他们实际登录时进行更新?我有什么事情可以参加以实现这一目标吗?

Using forms authentication, how can I ensure that the last login date is updated on each new visit to the site, rather just when they physically log in? Is there any event I can hook into to achieve this?

我无法使用会话状态,因为它在我正在开发的网站中被完全禁用(会话模块已被删除).

I can't use session state, as it is completely disabled in the web site I'm developing (the session module has been removed).

谢谢

推荐答案

我假设您使用的是cookie(否则我看不到记住我"的工作方式.)

I'm assuming that you are using cookies (I can't see how the "Remember me" would work otherwise).

当用户登录时,设置两个cookie,一个永久(如果选中了记住我")和一个临时(仅此会话).第二个是您用来授权用户的内容.

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

因此,在需要登录用户的页面上,查找会话cookie.如果找到,请照常继续.如果未找到,则查找永久cookie;如果找到,则查找用户,设置登录日期,然后设置会话cookie.(如果找不到永久cookie,则他就没有登录).

So, on a page where a user needs to be logged in, look for the session cookie. If found, continue as normal. If not found, look for the permanent cookie, if found, look the user in, set the log-in date, and set the session cookie. (If the permanent cookie isn't found, he just not logged in).

这篇关于如果“记住我",如何更新上次登录日期放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆