View all session in asp.net application
Can 开发者_高级运维I view all active session(s) in my ASP.NET application?
You could perform this in global.asax:
private static object _syncRoot = new object();
private static List<string> _activeSessions = new List<string>();
public static ReadOnlyCollection<string> ActiveSessions
{
get
{
lock(_syncRoot)
{
return new ReadOnlyCollection<string>(_activeSessions);
}
}
}
protected void Session_Start(object sender, EventArgs e)
{
lock(_syncRoot)
{
_activeSessions.Add(Session.SessionID);
}
}
protected void Session_End(object sender, EventArgs e)
{
lock(_syncRoot)
{
_activeSessions.Remove(Session.SessionID);
}
}
and then use the ActiveSessions
variable which will contain a list of all session ids.
精彩评论