C# 获取asp.net中的所有活动会话

C# 获取asp.net中的所有活动会话,c#,asp.net,session,C#,Asp.net,Session,我使用此代码获取我的asp.net网站中的所有活动会话,每个用户登录到我的网站时都会有会话[ID],下面代码中的IDsList类似于1,12,30100,这些数字是活动用户ID。我的代码在localhost上运行良好,但当我在windows Server 2008上运行我的网站时,它不起作用。我该怎么办 object obj = typeof(HttpRuntime).GetProperty("CacheInternal", BindingFlags.NonPublic | BindingF

我使用此代码获取我的asp.net网站中的所有活动会话,每个用户登录到我的网站时都会有会话[ID],下面代码中的IDsList类似于1,12,30100,这些数字是活动用户ID。我的代码在localhost上运行良好,但当我在windows Server 2008上运行我的网站时,它不起作用。我该怎么办

  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["ID"] != null)
                        {
                          IDsList += sess["ID"] + ",";
                        }
                    }
                }
            }
        }

你有什么错误吗?@AliShahrokhi没有什么