Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count number of sessions in ASP.net/c#

I need to count number of sessions but it dose not work when I say if numbers of sessions are 2 then do something. The example below is my code:

  // count curent session in order to keep two player
  if (HttpContext.Current.Session.Count == 2)
  {
     Response.Redirect("update.aspx");
  }

I place the above code in code behind. is there any other way that I can say: if number of sessions are 2 else do something...

like image 554
Sam Jelveh Avatar asked Nov 04 '22 18:11

Sam Jelveh


1 Answers

This is the count of session variables stored in the session for that user (msdn reference)...not the number of user sessions that exist currently.

You will need to store the session count outside of the session itself...perhaps in the Cache or Application cache.

Here are some SO questions to help implement this:

like image 99
davidsleeps Avatar answered Nov 09 '22 07:11

davidsleeps