如何在我的应用程序中计算在线用户? [英] How can I count the online users in my application?

查看:88
本文介绍了如何在我的应用程序中计算在线用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自己的系统来处理用户身份验证,并且数据库在mysql中维护.

I am using my own system to handle user authentication and the database is maintained in mysql.

现在,当我看到类似的东西

Now, when I see something like

System.Web.Security.Membership.GetNumberOfUsersOnline()

我想知道如何使用mysql获取用户数量.我在web.config中设置了一个数据库,该数据库已生成所有表,但是当我调用此预定义函数时,仍然会得到0.

I want to know how I can get the number of users, using mysql. I set, in web.config, a database that has all tables generated, but I still get 0 when I call this predefined function.

现在,我在mysql中拥有一个单独的数据库来维护角色.之所以有效,是因为它们已经生成了表格.现在,我想知道如何获取所有用户的数量,包括匿名用户.

Now, I have a separate database in mysql that maintains roles. It works because they have generated tables. Now I want to know how I can get the count of all users, including anonymous.

推荐答案

您可以尝试将其添加到global.asax:

You can try adding this to your global.asax:

void Application_Start(object sender, EventArgs e) {
    Application["OnlineUsers"] = 0;
}

void Session_Start(object sender, EventArgs e) {
    Application.Lock();
    Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
    Application.UnLock();
}

void Session_End(object sender, EventArgs e) {
    Application.Lock();
    Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
    Application.UnLock();
}

我在这里找到它:

http://aspdotnetfaq.com/Faq/How-to-show-number-of-online-users-visitors-for-ASP-NET-website.aspx

这基本上可以告诉您应用程序中当前有多少会话处于活动状态,无论它们是否已登录.您可以对其进行修改,以包括有关哪些用户已登录的详细信息,并且与您使用的成员资格系统无关.

This basically tells you how many sessions are currently active in your application regardless of whether they are logged in. You can modify this to include details about exactly which users are logged in and it's independent of whatever system you use for membership.

这篇关于如何在我的应用程序中计算在线用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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