Disclaimer: I just came up with this implementation because I thought it was an interesting and solvable problem. Thus, there may be some problems or details that I did not take into account. However, if you are using InProc session state, here is the solution.
: (, ), , Application_Start, Session_Start . Session_End . , , .
Global.asax
void Application_Start(object sender, EventArgs e)
{
Application["activeSessions"] = new System.Collections.Generic.List<HttpSessionState>();
}
void Session_Start(object sender, EventArgs e)
{
var activeSessions = (System.Collections.Generic.List<HttpSessionState>)Application["activeSessions"];
activeSessions.Add(this.Session);
}
void Session_End(object sender, EventArgs e)
{
var activeSessions = (System.Collections.Generic.List<HttpSessionState>)Application["activeSessions"];
activeSessions.Remove(this.Session);
}
SomePage.aspx
this.Session["someStr"] = DateTime.Now.ToString();
var activeSessions = (List<HttpSessionState>)Application["activeSessions"];
foreach (var session in activeSessions)
{
Response.Write("Session " + session.SessionID + "<br/>");
foreach (string key in session.Keys)
{
Response.Write(key + " : " + session[key] + "<br/>");
}
Response.Write("<hr/>");
}
: ( )
Session sj0sa255uizwlu45zivyfg2m
someStr : 8/28/2009 11:03:37 AM
----
Session 530b3sjtea22jm451p15u355
someStr : 8/28/2009 11:03:43 AM
----