在我的Global.cs中,
namespace HitCounters
{
public class Global : System.Web.HttpApplication
{
private static int totalNumberOfUsers = 0;
private static int currentNumberOfUsers = 0;
protected void Session_Start(Object sender, EventArgs e)
{
totalNumberOfUsers += 1;
currentNumberOfUsers += 1;
}
protected void Session_End(Object sender, EventArgs e)
{
currentNumberOfUsers -= 1;
}
protected void Application_End(Object sender, EventArgs e)
{
}
public static int TotalNumberOfUsers
{
get
{
return totalNumberOfUsers;
}
}
public static int CurrentNumberOfUsers
{
get
{
return currentNumberOfUsers;
}
}
}
}
并且,在Master Page的page_Load,
countOnline.Text = HitCounters.Global.CurrentNumberOfUsers.ToString();
countVisitor.Text = HitCounters.Global.TotalNumberOfUsers.ToString();
我认为Session_Start不起作用。 总访客数和在线用户数始终显示为零。 我想知道为什么!我错过了什么吗?
答案 0 :(得分:0)
在Web.config中配置<sessionState>
。