Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get List all active ASP.NET Sessions
Posted

Hi,
Run a loop on Session

C#
foreach(object obj in Session)
   {
        Response.Write(obj.ToString() + "  ");
   }


Hope it helps.
 
Share this answer
 
v2
hi,

you can collect informations about sessions in global.asax evets Session_Start and Session_End:
C#
private static List<string> _sessionInfo;
private static readonly object padlock = new object();

 public static List<string> Sessions
 {
            get
            {
                lock (padlock)
                {
                    if (_sessionInfo == null)
                    {
                        _sessionInfo = new List&lt;string&gt;();
                    }
                    return _sessionInfo;
                }
            }
  }

        protected void Session_Start(object sender, EventArgs e)
        {
            Sessions.Add(Session.SessionID);
        }
        protected void Session_End(object sender, EventArgs e)
        {
            Sessions.Remove(Session.SessionID);
        }


Best Luck
Happy Coding :)
 
Share this answer
 
v2
private List<string> getOnlineUsers()
{
List<string> activeSessions = new List<string>();
object obj = typeof(HttpRuntime).GetProperty("CacheInternal", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null, null);
object[] obj2 = (object[])obj.GetType().GetField("_caches", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(obj);
for (int i = 0; i < obj2.Length; i++)
{
Hashtable c2 = (Hashtable)obj2[i].GetType().GetField("_entries", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(obj2[i]);
foreach (DictionaryEntry entry in c2)
{
object o1 = entry.Value.GetType().GetProperty("Value", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(entry.Value, null);
if (o1.GetType().ToString() == "System.Web.SessionState.InProcSessionState")
{
SessionStateItemCollection sess = (SessionStateItemCollection)o1.GetType().GetField("_sessionItems", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(o1);
if (sess != null)
{
if (sess["loggedInUserId"] != null)
{
activeSessions.Add(sess["loggedInUserId"].ToString());
}
}
}
}
}
return activeSessions;
}

url :
http://stackoverflow.com/questions/8854176/get-a-list-of-all-active-sessions-in-asp-net[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900