如何prevent同时登录同在不同的PC相同的用户 [英] How to prevent simultaneous login with same user on different pcs

查看:190
本文介绍了如何prevent同时登录同在不同的PC相同的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须建立一个Intranet应用程序,用户必须登录才能完成特定任务...
我们必须确保没有应用程序用户是在同一时间登录一次以上。

We have build a intranet application where users have to login to do certain tasks... We have to make sure that no "application user" is logged in more than once at the same time.

所以我在此刻做的是,我存储当前的ASP.NET会话ID的数据库,然后我在每一个页面加载比较wheter他们是相同的或没有。会话ID是存储在数据库中时,用户登录

So what I do at the moment is that I store the current asp .net session id in the database and then i compare at every page load wheter they are same or not. The session id is stored in the database when the user logs in.

但是,通过使用这种检查,总有选择所需的数据库。所以,我不喜欢这种方式非常多。必须有解决这个问题的更优雅的方式,还是?

But by using this kind check, there is always a database select needed. So I don't like this way very much. There must be a more elegant way to solve this, or?

我们使用ASP .NET2,C#..

We use ASP .Net2, C#..

先谢谢您的任何输入

[信息更新]

我已经创建了一个自定义的MembershipProvider和一个自定义Membershippuser。
所述的MembershipUser有一个称为StartSession(串的sessionId)方法,其使用的,当在用户登录

I have already created a custom Membershipprovider and a custom Membershippuser. The Membershipuser has a method called "StartSession(string sessionId)" which is used, when the user logs in.

的其他方法CheckSession(串的sessionId)用于在每一个回传,并且它在当前会话ID与存储在数据库中的会话ID相比较。

The other method CheckSession(string sessionId) is used at every postback, and it compares the current session id with the session id stored in the database.

[更新]
谢谢大家对您的输入。我现在会用缓存来prevent永久数据库访问。我首先想到的已经有一类或者一些已经在处理这个问题。

[Update] Thanks everybody for your input. I will now use the cache to prevent permanent database access. I first thought that there is already a Class or something that is already handling this problem.

推荐答案

您现有的存储在数据库中该信息的做法是合理的,它帮助,如果事情扩大。

Your existing approach of storing this info in the DB is reasonable, it helps if things scale up.

然而,你也可以使用的System.Web.Caching.Cache对象跟踪用户当前会话为好。如果发现在缓存中的对象的信息未能回落到从数据库读取它,然后把这些信息在缓存中的后续请求的利益。

However you could also use the System.Web.Caching.Cache object to track a users current session as well. If finding the info in the cache object fails fall back to reading it from the DB then place that info in the cache for the benefit of subsequent requests.

这篇关于如何prevent同时登录同在不同的PC相同的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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