asax文件使用
using System;using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Xml.Linq;
namespace WzJyw.asax
{
public class Onle : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
Application["online"] = 0; //初始化在线人数变量值
}
protected void Session_Start(object sender, EventArgs e)
{
//在新会话启动时运行的代码,新会话开始表示有新的用户加入
Application.Lock(); //锁定Application
int NUM = (int)Application["online"] + 1;
Application.Set("online", NUM); //修改对象值,为自身+1
Application.UnLock(); //解除对象锁定
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
//在会话结束时运行的代码
//注意:只有在Web.config文件中的sessionstate模式设置为
//Inproc时,才会触发Session_End事件.如果会话模式设置为StateServer
//或SQLServer,则不会触发该事件
Application.Lock(); //锁定Application
int NUM = (int)Application["online"] - 1;
Application.Set("online", NUM); //修改对象值,为自身+1
Application.UnLock(); //解除对象锁定
}
protected void Application_End(object sender, EventArgs e)
{
}
}
}
我想把在线人数显示在Label上 但是不可以 大家帮忙下 谢谢了
public partial class Head2 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
lblOnle.Text = Application["online"].ToString(); //显示在线人数
Response.AddHeader("Refresh", "30"); //设置30秒刷新一次
}
}