这是我计算在线用户的代码 它在global.asax中运行良好,而且数量很好 但是当我从控制器调用它时它返回null
void Session_Start(object sender, EventArgs e)
{
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
Application.UnLock();
}
protected void Application_Start()
{
Application["OnlineUsers"] = 0;
}
控制器中的:
string strUsersOnline = HttpContext.Application["OnlineUsers"] as string;
ViewData["OnlineUsers"] = strUsersOnline;