如何计算asp.net c#中网站的访问者数量?
我使用下面的代码:
在global.asax页面中
<%@ Application Language="C#" %>
Run Code Online (Sandbox Code Playgroud)
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();
}
Run Code Online (Sandbox Code Playgroud)
在.aspx页面
<asp:Label runat="server" ID="lbluser" />
Run Code Online (Sandbox Code Playgroud)
在.aspx.cs中
protected void Page_Load(object sender, EventArgs e)
{
lbluser.Text = Application["NoOfVisitors"].ToString();
}
Run Code Online (Sandbox Code Playgroud)
应用程序计数器每小时重置为0 ...在计算用户数量方面我在哪里错了?...感谢你...