0

Hi,

I want to keep track of the number of visitors to my site.

I tried the following code in the Global.asax class,

public static int count = 0; 
void Application_Start(object sender, EventArgs e) 
{
 Application["myCount"] = count; 
}
 void Session_Start(object sender, EventArgs e)
 {
 count = Convert.ToInt32(Application["myCount"]); Application["myCount"] = count + 1; 
}

I am retrieving the value in the aspx page as follows:

protected void Page_Load(object sender, EventArgs e) 
{
int a;
    a = Convert.ToInt32((Application["myCount"]));
    Label4.Text = Convert.ToString(a);
    if (a < 10)
        Label4.Text = "000" + Label4.Text ;
    else if(a<100)
        Label4.Text = "00" + Label4.Text;
    else if(a<1000)
        Label4.Text = "0" + Label4.Text;
}

The above coding works fine. It generates the Visitors properly but the problem is when I restart my system, the count variable again starts from 0 which logically wrong.

I want the value of count to be incremented by 1 from the last count value.

So can anyone tell me how to accomplish this task?

Please help me out! Thanks in advance!

Edited by peter_budo: Correcting closing tag. Please use [/code] instead of [\code]

6
Contributors
5
Replies
19
Views
8 Years
Discussion Span
Last Post by mohan221
0

You should do analysis on your log files to deteremine the number of visitors. Check out "smarter stats."

2

Most of the Paid domains give this for free in their Control Panels. or you can try this

protected void Page_Load(object sender, EventArgs e)
    {
        Application.Lock();
        if(Application["HitCount"]!=null)
         {
            Application["HitCount"]=(int)Application["HitCount"]+1;
         }
        else
         {
             Application["HitCount"] =1;
         }
         Application.UnLock();
        lblInfo.Text="The page has been accessed ("+Application["HitCount"].ToString()+") times";
    }

or this might Help

http://www.stardeveloper.com/articles/display.html?article=2002102501&page=1

Kind Regards

Vuyiswa Maseko

Edited by peter_budo: Please use [code] instead of [quote]

Votes + Comments
neat, i didn't know about that
0

when you restart your system at that time IIS get close.Because of that all the information of users stored is get vanished.you have to use lock for that purpose.

-1

hi dear
You can also store count in another variable and make check the variables by applying condition code "if".

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.