在ASP.NET Identity中获取已登录用户的列表

编程入门 行业动态 更新时间:2024-10-26 19:30:46
本文介绍了在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中获取已登录用户的列表

本文发布于:2023-11-14 13:25:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587331.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户   列表   ASP   NET   Identity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!