Open Closed

Get All logged in users #3536


User avatar
0
imranStem created

How do I get all logged in users? I want to display the name of all logged in users on the page. If users logged out and or new users logged in the list should refresh. I will use the SignalR but I want the events where I can get the logged in or logged out event of users.

  • ABP Framework version: v5.2.1
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I don't know what the logged-in users mean.

    From your description, it sounds like a user who is using the application.

    Just a suggestion:

    You can use the SianglR and store the user information at the OnConnectedAsync event.

    public class ActiveHub:...
    {
       private readonly ICurrentUser _currentUser;
       
        ......   
    
       public override async Task OnConnectedAsync()
       {
            await AddActiveUserToCache();
        
            return base.OnConnectedAsync();
       }
       
       public async Task AddActiveUserAsync()
       {
           var userId = _currentUser....;
           .....
       }
       
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            await RemoveActiveUserAsync();
            return base.OnDisconnectedAsync(exception);
        }   
    
       public async Task RemoveActiveUserAsync()
       {
           ....
       }
    }
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    BTW, we have SecurityLog feature, logs are logged when a user logs in or out, it may helpful for you.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11