我正在尝试显示访问网站的用户数量和在线用户数量...我在全球应用程序类(.asax.cs)中编写了此代码
protected void Application_Start(object sender, EventArgs e)
{
Application.Add("counter", 0);
Application.Add("onlineCounter", 0);
}
protected void Session_Start(object sender, EventArgs e)
{
Application.Lock();
int _counter = (int)Application["counter"];
_counter++;
Application["counter"] = _counter;
Application.UnLock();
Application.Lock();
int _onlineCounter = (int)Application["onlineCounter"];
_onlineCounter++;
Application["onlineCounter"] = _onlineCounter;
Application.UnLock();
}
protected void Session_End(object sender, EventArgs e)
{
Application.Lock();
int _onlineCounter = (int)Application["onlineCounter"];
_onlineCounter--;
Application["onlineCounter"] = _onlineCounter;
Application.UnLock();
}
面对我的问题......当第一次运行网站时,值= 1和在线用户= 1并且在此之后永远不会改变,即使我打开网站的另一个标签或刷新网站