Hit count for Nopcommerce 2.5

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 年 前
Hit count access for nopcommerce 2.5.
I has implemented be in version 1.9 but I do not have the solution in version 2.5
12 年 前
In file Global.asax:

protected void Application_Start()
        {
            //initialize engine context
            EngineContext.Initialize(false);
            Application["OnlineUsers"] = 10;
            ........
}

        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started
            Application.Lock();
            Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
            Application.UnLock();
            int count_visit = 0;


            //Kiểm tra file count_visit.txt nếu không tồn tại thì
            if (System.IO.File.Exists(Server.MapPath("/count_visit.txt")) == false)
            {
                count_visit = 1;
            }
            // Ngược lại thì
            else
            {
                // Đọc dử liều từ file count_visit.txt
                System.IO.StreamReader read = new System.IO.StreamReader(Server.MapPath("/count_visit.txt"));
                count_visit = int.Parse(read.ReadLine());
                read.Close();
                // Tăng biến count_visit thêm 1
                count_visit++;
            }

            // khóa website
            Application.Lock();

            // gán biến Application count_visit
            Application["count_visit"] = count_visit;

            // Mở khóa website
            Application.UnLock();

            // Lưu dử liệu vào file count_visit.txt
            System.IO.StreamWriter writer = new System.IO.StreamWriter(Server.MapPath("/count_visit.txt"));
            writer.WriteLine(count_visit);
            writer.Close();
        }
        void Session_End(object sender, EventArgs e)
        {
            Application.Lock();
            Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
            Application.UnLock();
        }

In file View/Shared/Footer.cshtml

@HttpContext.Current.Application["count_visit"].ToString()

But error page.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.