我想跟蹤訪問我網站的訪問者數量。使用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