【发布时间】:2014-10-04 04:23:26
【问题描述】:
asp.net c#中如何统计网站的访问者数量?
我正在使用下面的代码:
在 global.asax 页面中:
<%@ Application Language="C#" %>
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["NoOfVisitors"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Application.Lock();
Application["NoOfVisitors"] = (int)Application["NoOfVisitors"] + 1;
Application.UnLock();
}
在 .aspx 页面中:
<asp:Label runat="server" ID="lbluser" />
在 .aspx.cs 中:
protected void Page_Load(object sender, EventArgs e)
{
lbluser.Text = Application["NoOfVisitors"].ToString();
}
应用程序计数器每隔一小时重置为 0 ... 我在统计用户数量时哪里出错了?
【问题讨论】: