【发布时间】:2009-10-02 09:20:28
【问题描述】:
我想跟踪我网站的访问者数量。
我在 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;
}
上面的编码工作正常。它可以正确生成访客,但问题是当我重新启动系统时,计数变量再次从 0 开始,这在逻辑上是错误的。
我希望 count 的值从最后一个 count 值增加 1。
那么谁能告诉我如何完成这项任务?
请帮帮我! 提前致谢!
【问题讨论】:
标签: asp.net