I'd like to restrict the number of concurrent users that are logged in to our portal depending on their purchased plan. For example, some plans allow 1 user and some 10.
How would I do this in .NET? I don't really know where to start.
How would I do this in .NET? I don't really know where to start.
SignalR solves this problem because SignalR creates a persistent web socket connection between a browser and web application. It's relatively easy to write code that detects the 11th user in real-time.
Another option is adding a last access DateTime column associated with the user. This column is used to find the active users and can be located in a user account table or another table of your design. Update this table each time the user accesses the
site.
Come up with a reasonable login expiration time 5, 10, 15 minutes of non use. Configure your login configuration for this expiration. Use the same time span to query the table when a user logs in to figure out if there are open logins. The worst case
scenario is a there are 10 concurrent users and one user walks away from there desk or closes the browser without logging out. The next user will need to wait for the expiration time before being able to login.
As a user won't necessarily disconnect explicitly a common approach is to keep track of the last http request date/time for each user and consider the user is active if this value is not older than x minutes.
Note though that AFAIK most plans are limiting the total number of users rather than the number of concurrent users. In addition to being easier it can also be less frustating for users to have access or not to your service rather to have to log multiple
times during the day to see if they currently have an available usage slot...
Agreed, but in this scenario it needs to be total number of concurrent users. I think my only option (unless anyone has any other thoughts) is to look at SingalR as users can potentially spend minutes/hours on a single page and still be considered active.
You can try with Application Cache to store users and managing the concurrent login restriction. It can be achieved in different ways like allowing only one login to an user or specific number of logins to an user login(2 concurrent login for an user). Also
there are other ways to store cache data like Redis.
Another post like this one;
Member
140 Points
590 Posts
Restricting number of concurrent users
Aug 22, 2020 05:31 PM|RageRiot|LINK
Hi,
I'd like to restrict the number of concurrent users that are logged in to our portal depending on their purchased plan. For example, some plans allow 1 user and some 10.
How would I do this in .NET? I don't really know where to start.
Many thanks
All-Star
53051 Points
23634 Posts
Re: Restricting number of concurrent users
Aug 23, 2020 11:19 AM|mgebhard|LINK
SignalR solves this problem because SignalR creates a persistent web socket connection between a browser and web application. It's relatively easy to write code that detects the 11th user in real-time.
Another option is adding a last access DateTime column associated with the user. This column is used to find the active users and can be located in a user account table or another table of your design. Update this table each time the user accesses the site.
Come up with a reasonable login expiration time 5, 10, 15 minutes of non use. Configure your login configuration for this expiration. Use the same time span to query the table when a user logs in to figure out if there are open logins. The worst case scenario is a there are 10 concurrent users and one user walks away from there desk or closes the browser without logging out. The next user will need to wait for the expiration time before being able to login.
All-Star
48530 Points
18075 Posts
Re: Restricting number of concurrent users
Aug 23, 2020 11:56 AM|PatriceSc|LINK
Hi,
As a user won't necessarily disconnect explicitly a common approach is to keep track of the last http request date/time for each user and consider the user is active if this value is not older than x minutes.
Note though that AFAIK most plans are limiting the total number of users rather than the number of concurrent users. In addition to being easier it can also be less frustating for users to have access or not to your service rather to have to log multiple times during the day to see if they currently have an available usage slot...
Member
140 Points
590 Posts
Re: Restricting number of concurrent users
Aug 23, 2020 12:27 PM|RageRiot|LINK
Agreed, but in this scenario it needs to be total number of concurrent users. I think my only option (unless anyone has any other thoughts) is to look at SingalR as users can potentially spend minutes/hours on a single page and still be considered active.
Participant
1426 Points
777 Posts
Re: Restricting number of concurrent users
Aug 23, 2020 05:22 PM|RagavanB|LINK
You can try with Application Cache to store users and managing the concurrent login restriction. It can be achieved in different ways like allowing only one login to an user or specific number of logins to an user login(2 concurrent login for an user). Also there are other ways to store cache data like Redis.
Another post like this one;
https://forums.asp.net/t/1960555.aspx?+Only+one+concurrent+login+per+UserID+in+Asp+net
http://teknohippy.net/2008/08/21/stopping-aspnet-concurrent-logins/
Ragavan B
Chennai.