.net 中怎样实现在线人数的统计和在线会员的信息显示

Lader_boy 2010-09-14 05:24:01
.net 中怎样实现在线人数的统计和在线会员的信息显示(就是把所有的会员的id,IP显示)!!

求高人解决!!万分感谢!
...全文
102 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
指尖魔术师 2010-09-14
  • 打赏
  • 举报
回复
在Global.ascx中做,这样是最简单的,但是统计太粗糙.如果想要精细的统计,得用别的办法了.

protected void Application_Start(Object sender, EventArgs e)
{
try
{
long lCount = 0;
StreamReader sdr = new StreamReader(Server.MapPath("App_Data/count.txt"));
string strCount = sdr.ReadLine();
if (strCount != null)
{
if (strCount.Trim().Replace(((char)13).ToString(), "") != "")
{
lCount = long.Parse(strCount);
}
}
sdr.Close();
Application.Lock();
Application["counter"] = lCount;
Application.UnLock();
}
catch { }
}

protected void Session_Start(Object sender, EventArgs e)
{
try
{
if (Request.ServerVariables["URL"].IndexOf("admin") == -1)
{
long lCount = 0;
lCount = long.Parse(Application["counter"].ToString()) + 1;
StreamWriter sw = new StreamWriter(Server.MapPath("App_Data/count.txt"));
sw.Write(lCount.ToString());
sw.Close();
Application.Lock();
Application["counter"] = lCount;
Application.UnLock();
}
}
catch { }
}

至于在线人数,在session_start里加入session判断就行了.有session的为登陆,没有的别为游客.

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧