August 5, 2014 06:22 by
Scott
This is only simple tutorial how to count number of visitors to a website in asp.net using C#. Just only brief description and hope you enjoy this tutorial
1. First thing to do is open Global.asax file and write the code as shown below
void Application_Start(object sender, EventArgs e)
{
Application["VisitorCount"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
Application["VisitorCount"] = (int)Application["VisitorCount"] + 1;
}
void Session_End(object sender, EventArgs e)
{
Application["VisitorCount"] = (int)Application["VisitorCount"] - 1;
}
2. Now open your aspx page in which you want to show the count and write the following code.
<div>
<asp:Label ID="lbl_Count" runat="server" ForeColor="Red" />
</div>
3. You’ll see the below code in the cs file on page load event
protected void Page_Load(object sender, EventArgs e)
{
lbl_Count.Text = Application["VisitorCount"].ToString();
}
Good luck and hope this tutorial help