1-4-2011 18:37:15
Tạo file global.asax
rồi code như sau :
public class Global : System.Web.HttpApplication
{
public const string USERSONLINE_KEY = "UsersOnline";
protected void Application_Start(object sender, EventArgs e)
{
Application[USERSONLINE_KEY] = 0;
}
void Session_Start(object sender, EventArgs e)
{
Application[USERSONLINE_KEY] = Convert.ToInt32(Application[USERSONLINE_KEY]) + 1;
}
void Session_End(object sender, EventArgs e)
{
Application[USERSONLINE_KEY] = Convert.ToInt32(Application[USERSONLINE_KEY]) - 1;
}
protected void Application_End(object sender, EventArgs e)
{
}
}
1/ app start tạo mới
2/ session start + 1
3/ session end -1
Như thế là cái biến Application[USERSONLINE_KEY] sẽ lưu kết quả số người đang online.