You can collect data about sessions in global.asax events Session_Start and Session_End (only in in-proc settings):
private static readonly List<string> _sessions = new List<string>();
private static readonly object padlock = new object();
public static List<string> Sessions
{
get
{
return _sessions;
}
}
protected void Session_Start(object sender, EventArgs e)
{
lock (padlock)
{
_sessions.Add(Session.SessionID);
}
}
protected void Session_End(object sender, EventArgs e)
{
lock (padlock)
{
_sessions.Remove(Session.SessionID);
}
}
You should consider use some of concurrent collections to lower the synchronization overhead. ConcurrentBag or ConcurrentDictionary. Or ImmutableList
https://msdn.microsoft.com/en-us/library/dd997373(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/dn467185.aspx
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…