ASP.NET - How to store value in session - Asked By bhanupratap singh on 21-Feb-17 06:15 PM

How to store user name of all users who have logged in, without going to the database. So that I could be able to know how many people are loged in at run tme without going to the databse
Robbe Morris replied to bhanupratap singh on 22-Feb-17 10:50 AM
You could try locking the Application["SessionCount"] variable and incrementing/decrementing a counter in the Session_OnStart and End events.  The session on end event does not always fire so this sort of thing is problematic to begin with whether you use a database to capture the last time a visitor viewed a page or whether you are storing this in the Application memory space or even application memory cache in ASP.NET.

You'll also need to come up with a timeframe to automatically expire a session from your count because of the on end event issue described above.

bhanupratap singh replied to Robbe Morris on 27-Feb-17 12:32 PM
Actually I am creating a chat app. In this I want to store user name as he logged in application without going to database. I do not have to count the user but need to know the user status till hi stay live in application. I do not want to store in database when user come to application, but I want to store user in session. So that I could keep on fetching it's name and keep on showing the status of user that he is currently on line without being interact with database.