0

i want to have number of people is online. i wrote this code in Session_End :

    protected void ()
    {
        int online = int.Parse(HttpContext.Current.Application["Online"].ToString());
        online -= 1;
        HttpContext.Current.Application["Online"] = online;
    }

Session_End Event not firing and online value is same. The Session_Start works well and gave correct value, so i think problem is in Session_End Event.

Session_Start Code Is :

    protected void Session_Start()
    {
        int online = int.Parse(HttpContext.Current.Application["Online"].ToString());
        online += 1;
        HttpContext.Current.Application["Online"] = online;
        //After This Codes ,i add Visit Log Using user ip into database(may help)
    }
  • 1
    Does this answer your question? [Session\_End does not fire?](https://stackoverflow.com/questions/4813462/session-end-does-not-fire) – शेखर Apr 14 '22 at 14:20
  • If you need to maintain state beyond a single session and Application, you need some form of state persistence, typically a database, that you write/read through too. You can try something like this `var loggedInUsers = (Dictionary)HttpRuntime.Cache["LoggedInUsers"]` – Md Farid Uddin Kiron Apr 15 '22 at 07:50

0 Answers0