我面臨着一個老問題,它讓我非常困惑。所以我需要你的建議來確保我一直在用正確的方式。 我的需求是算在我的網站訪問者的數量,所以我在Global.asax文件編碼:在網站中統計訪客總數的正確方法是什麼?
void Application_Start(object sender, EventArgs e)
{
// Get total visitor from database
long SiteHitCounter = 0;
int CurrentUsers = 0;
SiteHitCounter = MethodToGetTotalVisitorFromDatabase();
Application["SiteHitCounter"] = SiteHitCounter;
Application["CurrentUsers"] = CurrentUsers;
}
void Application_End(object sender, EventArgs e)
{
// Update total visitor to database when application shutdown
MethodToUpdateTotalVisitorToDatabase((long)Application["SiteHitCounter"]);
}
void Session_Start(object sender, EventArgs e)
{
// Increase total visitor and online user
Application["SiteHitCounter"] = (long)Application["SiteHitCounter"] + 1;
Application["CurrentUsers"] = (int)Application["CurrentUsers"] + 1;
}
void Session_End(object sender, EventArgs e)
{
// Decrease online user
Application["CurrentUsers"] = (int)Application["CurrentUsers"] - 1;
}
然後,我用變量應用[「SiteHitCounter」]和應用[CurrentUsers「]另一個C#後面的代碼文件在網頁上顯示它們 我面臨的問題是,當我將它發佈到共享主機時,網站無法顯示正確的訪問者總數量
我需要你對此的建議。
謝謝, Tien
只需使用http://www.google.com/analytics/並讓他們處理問題:) – 2010-08-14 15:29:37