如何防止同一用户从两个不同的浏览器登录到asp.net网站 [英] How do i prevent same user login into the asp.net website from two different browsers

查看:215
本文介绍了如何防止同一用户从两个不同的浏览器登录到asp.net网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

In my asp.net website, I want to prevent same user login into website simultaneously from two different browsers. In order to do so, I had created table (say userloggedin)  that will store user id and time once user login. when user attempts to login from different browser, user will not be redirected into website from that new browser he is attempting to login (if user's record is in userloggedin table). 

User's record will be deleted when user logout, thus clearing log for allowing next time login.

The problem i am facing using this approach is when user clicks on close button from title bar, browser closes. Here, record will not be deleted from userloggedin table.( i need to delete from this table to allow future login). I had used window.onbeforeunload and kept a code to delete from userloggedin in here. But this function gets fired on every postback. 

How can i delete record from userloggedin table on click of close button? Any alternative approach is welcome..





我有什么试过:



我创建了一个用户登录表来存储登录用户的记录。然后,当用户从另一个浏览器登录时,会检查该表。如果此表中有他的数据,则不允许他登录。



What I have tried:

I had created a table userloggedin to store record of user logged in. Then, when user login from another browser, this table is checked. If there is his data in this table, he is not allowed to login.

推荐答案

请参阅此处的第5点



你不应该花时间去做的事情| ASP.NET论坛 [ ^ ]
See point 5 here

Things you shouldn't spend time doing | The ASP.NET Forums[^]


通常,用户将在一段时间处于非活动状态后自动退出。使用事件或任何内容注销用户,因为可能还会丢失互联网连接或用户计算机完全崩溃。所以你永远不能确定。

当用户从另一个浏览器成功登录时,您只需先清除旧记录,然后再编写新记录或覆盖现有记录。这将有效地在其他浏览器中注销用户。



这是所有默认实现的方式,可以通过使用提供登录功能的正确模板启动新的Web项目来简单地创建。允许用户多次登录通常要困难得多,因为默认实现清除了另一个会话,并在另一个浏览器中注销了同一个用户。



祝你好运!
Normally a user will be automatically signed out after some time beeing inactive. Logout users using events or anything because there could also be a loss of the internet connection or a complete crash of the user's computer. So you can never be sure.
When a user does a succesful login from another browser you simply clear the old record first before writing a new one or overwrite the existing. This will effectively logout the user in the other browser.

This is all default implementation by the way that can be simply created by starting a new web project with the right template providing login functionality. It is normally much harder to allow a user to be logged in multiple times because the default implementation clears the other session and with it logs out the same user in another browser.

Good luck!


这篇关于如何防止同一用户从两个不同的浏览器登录到asp.net网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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