列出所有活动会话ASP.NET [英] List all active ASP.NET Sessions
本文介绍了列出所有活动会话ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何列出(和遍历)目前所有的ASP.NET会话?
How can I list (and iterate through) all current ASP.NET sessions?
推荐答案
通过所有会话迭代很可能是不太线程安全的。
但是你可以收集有关会议的信息在Global.asax中evets在session_start和Session_End中:
Iterating through all sessions will be probably not very thread-safe. But you can collect informations about sessions in global.asax evets Session_Start and Session_End:
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<string>();
}
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);
}
这篇关于列出所有活动会话ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文