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.

    image.png

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on April 11, 2025, 10:10