简体   繁体   English

限制对Asp.Net应用程序的并发访问

[英]Limit concurrent access to Asp.Net application

I want to limit concurrent access to internet or intranet web applications. 我想限制对Internet或Intranet Web应用程序的并发访问。

I want to be able to allow certain number of concurrent access, let's say I want to allow maximum 20 concurrent access using the same username. 我希望能够允许一定数量的并发访问,比方说,我希望使用相同的用户名最多允许20个并发访问。

I can imagine creating a session at the login time and save it into DB with incrementing a counter, but there is no way to delete it from the DB and decrement the counter if user is logged off, as user may just close the browser. 我可以想象在登录时创建一个会话,然后通过增加计数器将其保存到数据库中,但是如果用户注销,则无法从数据库中删除该会话并减少计数器,因为用户可能只是关闭浏览器。

Guys, what is the best way from your opinion? 伙计们,您认为最好的方法是什么?

Thanks, 谢谢,

You are right in that you cannot know if a user just kills his browser or pulls the cord. 正确的是,您不知道用户是杀死了他的浏览器还是拔出了电源线。

Create a timer that does an Ajax call every 30 seconds and log it. 创建一个计时器,每30秒执行一次Ajax调用并将其记录下来。 If a user isn't in this log for 60 seconds - throw'em out at the server. 如果用户60秒钟内不在此日志中,请在服务器上将其丢弃。
This won't stop someone from leaving their browser open over the night and hogging a slot though. 这不会阻止某人在夜间打开浏览器并占用一个插槽。

There is another answer mentioning an "last active" field. 还有另一个答案提到“最后一个活动”字段。 This on the other hand messes up when someone needs to leave their browser open to look at something for more than the timeout limit of minutes. 另一方面,当有人需要让浏览器保持打开状态以查看某物超过超时时间(分钟)时,这种情况会变得混乱。

If someone is thrown out due to the user/timeout limit; 如果由于用户/超时限制而将某人赶出去; I think it would be nice to have them automagically logged in again totally transparently if there is a slot open again. 我认为,如果再次打开某个插槽,让它们完全透明地自动重新登录会很好。

Without thinking too hard about it I believe this solution will give birth to other problems. 不用考虑太多,我相信这种解决方案会带来其他问题。

Edited away: 删除:
As I commented - 20 users - are you really solving the right problem? 正如我评论的(20个用户),您真的在解决正确的问题吗?

You may wish to have a "lastactive" field on your session. 您可能希望会话中有一个“ lastactive”字段。 When someone attempts to log in or otherwise create a session, you can query for all sessions that have been active within a period of time (say 15 minutes), and use the resulting count to tell you how many concurrent sessions are active. 当某人尝试登录或以其他方式创建会话时,您可以查询一段时间(例如15分钟)内所有活动的会话,并使用结果计数告诉您有多少个并发会话处于活动状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM