如何避免具有相同UserName和Pwd的多个登录 [英] How to avoid Multiple Logins With Same UserName and Pwd

查看:149
本文介绍了如何避免具有相同UserName和Pwd的多个登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我使用ASP.NET,C#,SQL-Server创建Web应用程序。并且在IIS服务器中托管。它工作正常。



我需要避免使用相同用户名的多个登录。

用户不应该使用其他系统的相同用户名登录。



它应该显示已经登录的消息。



请帮我解决这个问题。那么这个步骤是什么? ?



谢谢。

Dear Friends,

I have Create a Web application using ASP.NET, C#, SQL-Server. and Hosted in IIS server.Its working fine.

I need to avoid multiple logins with Same Username.
The User should not log in with same username from other systems.

It should Display a message Already Logged in.

Please Help me this problem. SO WHAT ARE THE STEPS TO DO THIS ? ?

Thanks.

推荐答案

我认为最简单的方法是管理一个列表在Application变量中登录用户。因为这个变量可供所有用户使用,甚至可以登录用户。



1.在应用程序变量中添加登录用户列表,最初为空。

2.当有人登录时检查他的名字是否在列表中。

3.如果没有,那么让他登录然后将他的名字添加到列表中。

4.当有人注销时从列表中删除名称。



因此,如果用户登录,您的方案将在第二点处理将不允许再次登录。



注意:这假设您只有一台服务器而不是Web场。



如果您有一个Web场,那么您需要在数据库中执行此操作。然后算法将是b $ b

1.在db表中添加登录用户列表,最初为空。

2.当某人登录检查他的名字是否在列表中。

3.如果没有,那么让他登录,然后将他的名字添加到列表中。

4.当有人登录时关闭从列表中删除名称。
I think the easiest way to do this is by managing a list of logged in users in Application variable. since this variable is available to all users and even for not logged in user.

1. add the list of logged in user in application variable, initially empty.
2. when someone logs in check if his name is in the list.
3. if not then let him log in and then add his name to the list.
4. when someone logs off remove the name from the list.

so your scenario will be handled in 2nd point when if user is logged in he will not be allowed to log in again.

Note: This is assuming that you have only one server and not web farm.

If you have a web farm then you need to do this in database. the algo will then be

1. add the list of logged in user in a db table, initially empty.
2. when someone logs in check if his name is in the list.
3. if not then let him log in and then add his name to the list.
4. when someone logs off remove the name from the list.


Hai,



如果用户关闭浏览器,则表的使用失败不幸的是。



如您所知,Cache是​​一个特定于应用程序的对象,不是用户特定的,在用户可以设置的指定时间后可以过期。



最好的方法是使用缓存类并使用最小的过期时间(例如2分钟)将已使用的ID添加到缓存中。还将用户ID和会话ID放入会话变量中。 />


在global.asax文件中的Application_PreRequestHandlerExecute事件中编写代码。



每次点击,读取会话ID来自会话变量a nd检查此会话ID是否与session.sessionID值匹配。如果不匹配,则将用户重定向到注销页面。(由于用户已登录其他会话)



如果匹配,则从缓存中检查用户ID。如果它为null,则再次将用户ID(从会话变量读取)设置为具有相同可过期时间(例如2分钟)的缓存。



由于这种方法,如果用户闲置超过缓存到期时间(例如2分钟),则同一用户可以登录其他会话。



通过在登录期间从缓存中检查用户ID,我们可以避免多次登录。



谢谢

Mani
Hai,

The using of table is failure in case of user closes the browser unfortunately.

As you know,Cache is an application specific object not user specific and this can expirable after the specified time which can set by the user.

The best of approach is use the cache class and add used ID to cache with minimal expired time(say 2 minutes).Also put user ID and session ID into session variable.

Write the code in Application_PreRequestHandlerExecute event in global.asax file.

At each hit, read the session ID from session variable and check this session ID is match with session.sessionID value.If not match redirect the user to logout page.(Since the user already logged in some other session)

If match then check the user ID from cache.If it is null then again set the user ID(Read from session variable) into cache with same expirable time(say 2 minutes).

Due to this approach,if the user is idle beyond cache expiry time (say 2 minutes),the same user can login in some other session.

By checking the user ID from cache during login we can avoid multi-login.

Thanks
Mani






在数据库表中再取一列作为位。默认情况下将其设置为0(表示未登录)。如果用户登录只检查该位,如果为0表示用户可以登录(登录后设置为1,再次注销后再设置为0)否则用户无法登录。

否则,您也可以使用应用程序管理来阻止用户使用相同的用户ID和密码进行多次登录。

如果是会话超时,您可以使用委托来触发事件。看看此处 [ ^ ]。





这可能会对你有所帮助。

一切顺利。

--AK
Hi,

Take one more column in your database table as bit. By default set it to 0(Means not logged in). If a user logs in just check for the bit, If it is 0 means user can log in(after logging in set it to 1 and after log out again set it to 0) otherwise user cannot log in.
Else you can use application management also to prevent the user from multiple login with same userid and password.
In the case of session timeout you can fire the events using delegates. Have a look Here[^].


This may help you.
All the best.
--AK


这篇关于如何避免具有相同UserName和Pwd的多个登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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