Introduction: Site Visitor Count

In this post, we will learn about how to ‘get site visitor count in asp.net using C#.Net’ with an example.

Description:

In my previous post I have explained various topics like Convert generic list to datatable in Asp.Net C#.Net. Abstract Class in C# with Example,Routing in Asp.Net MVC with Example,Use of Global.asax in Asp.net.
Now in this post, I will explain about how to get site visitor in asp.net with appropriate example.

First of all, Create one sample web application in visual studio and add the Global.asax file in it.

write the below code in the Global.asax file.

using System;
namespace SiteVisitor
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            Application["VisitorsCount"] = 0;
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            Application.Lock();
            Application["VisitorsCount"] = (int)Application["VisitorsCount"] + 1;
            Application.UnLock();
        }       
    }
}

Furthermore add one .aspx page and write below code in it.

<asp:Label ID="lblCount" runat="server"></asp:Label>

In addition, Write below lines of code in the code-behind file of above aspx page.

protected void Page_Load(object sender, EventArgs e)
{
       lblCount.Text ="Total Visitor = " + Application["VisitorsCount"].ToString();
}

 

site visitor count

visitor

Read :

Finally, I hope you got an idea about how to get a count of site visitor in asp.net. I would like to have feedback from my blog readers so, Your valuable feedback, question, or comments about this article are always welcome.

One thought on “Get Count of Visitors in Website using Asp.net and C#.Net

  1. increase says:

    Нeу! This iѕ my 1st comment here so I just wanted to give a quick shout
    оut and say I reallү enjoy reading ʏour posts. Can yоu recommend any other blogs/websites/forums that c᧐ver the ѕame subjects?
    Thank yoս so much!

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website