在ASP.NET Identity中获取已登录用户的列表 [英] Getting a list of logged-in users in ASP.NET Identity

查看:142
本文介绍了在ASP.NET Identity中获取已登录用户的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用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

其中ApplicationDbContext随ASP.NET Web应用程序模板一起提供,并且扩展了IdentityDbContext.

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

但是IdentityUser类似乎无法查询登录状态.

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

谢谢您的指导.

推荐答案

对此没有内置支持.实现此目的的一种简单方法是向用户添加LastActivityDate,只要用户在您的网站上执行某项操作,该方法就会更新.然后,您可以针对该查询进行查询,以寻找在合理时间(例如30分钟)内处于活动状态的用户,并显示该信息.

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.

这篇关于在ASP.NET Identity中获取已登录用户的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆