每个UserId的唯一会话 [英] Unique Session for every UserId

查看:90
本文介绍了每个UserId的唯一会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在研究Asp。净申请。我的reuqiremnt是我想在登录后为每个用户ID维护唯一的会话。

例如,如果用户IDABC已经登录,那么如果同一用户尝试从任何浏览器登录,那么它不应该允许访问。

Hi,
I am working on Asp. net application. My reuqiremnt is i want to maintain unique session for each userid after login.
For example, if userid "ABC" is already logged in then next if same user tries to login from any browser then it should not allowed to access.

推荐答案

你可以很容易地做到这一点,但你必须添加一些警告。

这很简单 - 您所做的就是在登录数据库中添加登录字段,并在他们尝试登录时进行检查。如果已设置,则拒绝登录。如果不是,请将它们登录并进行设置。



问题出现时,他们不会退出。如果他们的浏览器或页面因任何原因关闭而没有先实际登出(这非常容易),那么他们将永远无法再次登录,除非你重置它们。



因此它会使登录字段成为日期/时间字段并检查它 - 当它们与您的应用程序交互时,将日期时间更新为终止时间并检查它们是否已过期尝试登录。如果他们注销,请将到期时间设置为1/1/2001并且您已全部设置。



如果您将终止期限设置为标准会话长度然后它们一起工作没有问题 - 如果他们没有注销,他们必须等待10或20分钟,但然后他们可以再次登录。
You can do that quite easily, but you have to add some caveats.
It''s pretty simple - all you do is add a "logged in" field to your login database and check it when they try to log in. If it is set, then refuse the login. If it isn''t, log them in and set it.

The problem comes when they don''t log out. If their browser or the page closes for any reason without actually logging them out first (which is pretty damn easy to do) then they will never be able to log in again, unless you reset them.

So it would make the "logged in" field a date/time field and check it - when they interact with your app, update the datetime to a "termination time" and check if that has expired when they attempt a log in. If they do log out set the expiry time to 1/1/2001 and you are all set.

If you set the termination period to your standard session length then it all works together without problems - if they don''t log out, they have to wait 10 or 20 minutes, but then they can log in again.


请参阅以下链接



http://www.sprklab.com/notes/5-how-to-allow-only-one-user-per-account-in-aspnet [ ^ ]
Refer the following link

http://www.sprklab.com/notes/5-how-to-allow-only-one-user-per-account-in-aspnet[^]


参考类似的主题:为每次用户使用应用程序创建唯一的会话ID。 [ ^ ]
Refer similar thread: To Create a unique session ID for every time user us the application.[^]


这篇关于每个UserId的唯一会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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