get session ID in ASP.Net

后端 未结 6 1612
滥情空心
滥情空心 2021-02-02 07:31

how can I get IDs of all current sessions?

6条回答
  •  臣服心动
    2021-02-02 08:22

    According to Dino Esposito each session is stored in the application's Cache and with some work you can retreive this information:

    DataTable dt = new DataTable();
    dt.Columns.Add("SessionID", typeof(string));
    foreach(DictionaryEntry elem in Cache) {
        string s = elem.Key.ToString();
        if (s.StartsWith("System.Web.SessionState.SessionStateItem")) {
            DataRow row = dt.NewRow();
            char[] parms = {':'};
            string[] a = s.Split(parms);
            row["SessionID"] = a[1];
            dt.Rows.Add(row);
        }
    }
    

提交回复
热议问题