Click here to Skip to main content
14,699,500 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all ,

I am trying to get the number of visitors of my website.And this is what iam doing:

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
      ' Fires when the application is started
      ' da.Update(0, 1)
      count = da.Select_visitors_count
      Application("myCount") = count
  End Sub

  Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
      ' Fires when the session is started

      Application("myCount") = count + 1
      da.Update(Application("myCount"), 1)
  End Sub

So iam getting the count of visitors using typed dataset into the count and incrementing the value.But the problem is that it is being incremented once by 20 and another time by 10 and another time by 14....S what is wrong ?

Knowing that on local host it is great.

Thanks.
Posted

Why don't you simply write a stored proc that increments the counter (and maybe sets a date column to indicate the datetime of the last update), and leave it at that?

At that point, you can retrieve it any time you want and you'll know how many users have accessed your site as of the saved datetime.
   
void Application_Start(object sender, EventArgs e)
 {
        int num=1; //for the first visitor
        Application["VisitorCount"]= num;
 }



void Session_Start(object sender, EventArgs e)
{
        int num = Int32.Parse(Application["VisitorCount"].ToString());
        num++;
        Application["VisitorCount"] = num;
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900