网站总数登录用户代码 [英] Code For Counting total Login User of website
本文介绍了网站总数登录用户代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
我想显示当前正在网站上登录的网站用户总数.
我正在Google上搜索代码以计算已登录用户总数,但尚未找到.i需要该代码
谢谢你
Gulam Hussain
Hello Friends,
I want to show total users of the website who''s currently login on the website.
i m searching the code on the Google to count total logged-In User but not found yet.i Need that code
thanking you
Gulam Hussain
推荐答案
这看起来像是一个合理的答案:
跟踪用户活动 [
This looks like a reasonable answer:
Tracking User Activity[^]
Regards
Espen Harlinn
您需要使用Session_Start和Session_End事件处理程序:
You need to use Session_Start and Session_End event handlers:
public class Global : System.Web.HttpApplication
{
public static int OnlineUsers { get; set; }
void Application_Start(object sender, EventArgs e)
{
OnlineUsers = 0;
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
OnlineUsers++;
}
void Session_End(object sender, EventArgs e)
{
OnlineUsers--;
}
}
还有您的代码:
And your code behind:
lblOnlineUsers.Text = "Online Users: "+ Global.OnlineUsers;
如果我的回答对您有帮助,请投票.
Please vote if my answer will help you.
您可以使用会话变量.
使用会话变量,您必须计算在线用户数..
为此,请使用以下代码:
You Can use session variable.
Using Session Variable You Have To Count The The Number Of Online Users..
For That Use The Below Code :
void OnlineUser_Start(object sender, EventArgs e)
{
OnlineUser["User"] = 0; //Initially By Zero(0).
}
//Method For Counting Online Users...
void UserCount_Start(object sender, EventArgs e)
{
int count;
count = (int)OnlineUser["User"];
count = count + 1;
OnlineUser["User"]=count;
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(OnlineUser["User"].ToString());
}
这篇关于网站总数登录用户代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文