我想跟踪访问我网站的访问者数量。使用ASP.Net和C计算Web站点中的访问者数量#
我试图在Global.asax类下面的代码,
<script runat="server">
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;
}
</script>
我在aspx页面检索值如下:
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;
}
上述编写工作正常。它正确地生成访问者,但问题是当我重新启动我的系统时,count变量再次从0开始,这在逻辑上是错误的。
我要计数的值由1从最后的计数值递增。
因此,谁能告诉我如何完成这个任务?
请帮我一把! 在此先感谢!
好的,谢谢你的回复。 如果你不介意,你能告诉我该怎么做吗?并将它存储在数据库或文本文件中是否有利? – Sheetal