Pages

Monday, 20 February 2012

Count the Visitor level in ASP.NET using C# code

//Add the following call in Global.asax file
void application_start(object sender,EventArgs e)
{
       Application["vcount"] = 0;
}
void session_start(object sender,EventArgs e)
{
       Session["ucount"] = 0;
       Application.Lock( );
       Application["vcount"] = (int)Application["vcount"] + 1;
       Application.Unlock( );
       Session["ucount"] = Application["vcount"];
}
//Then add the following in the page Load part
protected void Page_Load(object sender, EventArgs e)

{
         Label1.Text = "You are Visitor No:" + Session["ucount"].ToString( ) ;
         Label2.Text = "Total Visitors:" + Application["vcount"].ToString( ) ;
 }

No comments:

Post a Comment