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["NoOfVisitors"] = (int)Application["NoOfVisitors"] + 1;
<asp:Label runat="server" ID="lbluser" />
protected void Page_Load(object sender, EventArgs e)
lbluser.Text = Application["NoOfVisitors"].ToString();
If your application is hosted in IIS and has an application pool, you can check the Application Pool Recycling Settings. Depending on your version, the default is 1740 or 29 hours. Maybe the pool for your application is configured to 60 or around that value? The next setting to check is the Idle Time Out. I believe its default value is 20 on a new server. You can set this to 0. I recommend you read about these settings prior to changing them.