跟踪已登录的用户 [英] Tracking users who have logged in

查看:85
本文介绍了跟踪已登录的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何跟踪使用mvc登录的用户

How to track users who have logged in using mvc

推荐答案

最简单的方法是添加一个静态计数器,该计数器将在Session_Start上递增并在Session_End上递减。你需要在会​​话中添加一个变量(如Session [IsActive] = true;),以允许Session_end正常启动。



如果你想要跟踪用户你需要添加一个静态IEnumerable(或者我认为是一个类,如果你愿意的话),它同样由Session Start和end事件操纵,但是使用名称或数据库键。



The easiest way would be to add a static counter that would increment on Session_Start and decrement on Session_End. You'll need to add a variable (like Session["IsActive"] = true;) to the session to allow Session_end to fire properly.

If you want to track by-user you will need to add a static IEnumerable (or a class I suppose, if you prefer) that is similarly manipulated by the Session Start and end events, but using either names or your database keys.

public class MvcApplication : HttpApplication
{
    public static List<int> UsersOnline{ get; set; } // or string, or custom class

    protected void ApplicationStart()
    {
        UsersOnline = new List<int>();
    }

    protected void Session_Start(object sender, EventArgs e)
    {
        UsersOnline.Add(/* Hook to DB or Directory here */);
    }

    protected void Session_Start(object sender, EventArgs e)
    {
        UsersOnline.Remove(/* Hook to DB or Directory here */);
    }
    ...
}
</int></int>


这篇关于跟踪已登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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