Get,online,users,from,session

vincent 7/29/2016 1people says helpful

This code will return you all online users of your website using sessions.

C#
 public static List<String> GetOnlineUsers()
        {
            var activeSessions = new List<String>();
            var obj = typeof(HttpRuntime).GetProperty("CacheInternal", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null, null);
            var obj2 = (object[])obj.GetType().GetField("_caches", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(obj);
            for (int i = 0; i < obj2.Length; i  )
            {
                var 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")
                    {
                        var sess = (SessionStateItemCollection)o1.GetType().GetField("_sessionItems", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(o1);
                        if (sess != null)
                        {
                            var sessionInfo = (sess["ict_user"] as SessionInfo);
                            if (sessionInfo != null)
                            {
                                string kullanici = sessionInfo.DS_KULLANICI;
                                string loginDate = sessionInfo.LoginDate.ToShortDateString()   " - "  
                                                   sessionInfo.LoginDate.ToLongTimeString();
                                activeSessions.Add(kullanici " " loginDate);
                            }
                        }
                    }
                }
            }
            return activeSessions;
        }
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments