asp.net - 关于获取在线用户的方式(不知道有没好的办法)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
Session["name"] = "1";
Session["name1"] = "2";
Session["name2"] = "3";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] a = new string[Session.Keys.Count];
for (int i = 0; i < Session.Keys.Count; i++)
{
a[i] = Session[i].ToString();
}
Response.Write(a.Length.ToString());
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
Session["name"] = "1";
Session["name1"] = "2";
Session["name2"] = "3";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] a = new string[Session.Keys.Count];
for (int i = 0; i < Session.Keys.Count; i++)
{
a[i] = Session[i].ToString();
}
Response.Write(a.Length.ToString());
}
}
这是我的后台代码,已经获取了session的个数,获取值也懒的写了,都在string数组里.
有些人会问这样会对服务器负载太大,但是我们可以从服务器端把这处理完的个string数组给一个全局的string数组啊
这样每几十秒刷一次,然后用户统计的时候给他这个全局的string数组不就得了,一个string数组能浪费多少资源?!
大家有什么好办法` wating...