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

僤鯓⒐⒋嵵緔 提交于 2019-12-03 11:43:01

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/22995653/getting-a-list-of-logged-in-users-in-asp-net-identity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!