locked
Restricting number of concurrent users RRS feed

  • Question

  • User-195907812 posted

    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

    Saturday, August 22, 2020 5:31 PM

All replies

  • User475983607 posted

    RageRiot

    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.

    Sunday, August 23, 2020 11:19 AM
  • User753101303 posted

    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...

    Sunday, August 23, 2020 11:56 AM
  • User-195907812 posted

    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.

    Sunday, August 23, 2020 12:27 PM
  • User-46109667 posted

    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/

    1. Application Cache(in memory)
    2. External Data Caching(like Redis) 
    Sunday, August 23, 2020 5:22 PM