How do I count the number of visitors for website in asp.net c#?
I am using the code below:
In global.asax page:
<%@ 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();
}
In .aspx page:
<asp:Label runat="server" ID="lbluser" />
In .aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
lbluser.Text = Application["NoOfVisitors"].ToString();
}
The application counter is resetting to 0 every one hour ... Where have I erred in counting the number of users?