Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of logged-in users in ASP.NET Identity

I'm getting started with ASP.NET Identity, but I've been unable to find a way to fetch a list of the current logged in users. To get all users I can just user

new ApplicationDbContext().Users

where ApplicationDbContext comes with the ASP.NET Web Application template, and extends IdentityDbContext.

But the IdentityUser class does not seem to have any way to query for the logged in status.

Thank you for any pointers.

like image 841
So Many Goblins Avatar asked Apr 10 '14 18:04

So Many Goblins


1 Answers

There is no built in support for this. One simple way you could implement this would be to add a LastActivityDate to your user, which is updated whenever a user does something on your site. Then you can just query against that looking for users who are active within some reasonable time, like 30 minutes and display that.

like image 84
Hao Kung Avatar answered Oct 19 '22 11:10

Hao Kung