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!