1

i'm trying to show the number of users that visits website and the number of online users... i wrote this code in Global Application Class(.asax.cs)

    protected void Application_Start(object sender, EventArgs e)
    {
        Application.Add("counter", 0);
        Application.Add("onlineCounter", 0);
    }

    protected void Session_Start(object sender, EventArgs e)
    {
        Application.Lock();
        int _counter = (int)Application["counter"];
        _counter++;
        Application["counter"] = _counter;
        Application.UnLock();
        Application.Lock();
        int _onlineCounter = (int)Application["onlineCounter"];
        _onlineCounter++;
        Application["onlineCounter"] = _onlineCounter;
        Application.UnLock();
    }

    protected void Session_End(object sender, EventArgs e)
    {
        Application.Lock();
        int _onlineCounter = (int)Application["onlineCounter"];
        _onlineCounter--;
        Application["onlineCounter"] = _onlineCounter;
        Application.UnLock();
    }

the problem that face me ... when running the website for first time the value of visits = 1 and online users = 1 and never change after that even when i open another tabs of the website or refresh the website

  • using another Tab of the same browser does not start a new session, you need another browser or using browser private mode – Khatibzadeh Mar 07 '18 at 02:21
  • @Khatibzadeh i tried it with another browser and the problem still exist – Mohamed Elhout Mar 07 '18 at 14:59
  • I personally checked the following and it works like a charm. using multiple browsers or incognito mode on chrome or private browsing on Firefox needed to create a new session at the same time in dev mode. https://stackoverflow.com/a/6218525/3580273 – Khatibzadeh Mar 07 '18 at 19:29
  • @Khatibzadeh thanks man it's working – Mohamed Elhout Mar 07 '18 at 22:49

0 Answers0