As with Disconnecting, use this to clean-up any static resources or allocation tables related to a user session. DisconnectionEx adds additional information about the disconnect to assist in managing any additional resources associated with the session.
Contents of the sessionInfo Dictionary includes:
Key |
Value |
SessionKey |
The special identifier of this unique session |
SessionOwner |
The SessionOwner--similar to the http context User.Identity.Name but for situations where this may not be available. If no user identity has been configured, this will be the IP address of the client that connected to this session. |
SessionID |
Simple string portion of the SessionKey that is just the integer of the session starting at "1" |
ConnectedSeconds |
Number of seconds that the session was connected. |
UserLocation |
User's IP address |
/// <summary>
/// DisconnectingEx is used for managing assigned LUnames or other details on a user with
/// additional information provided in the sessionInfo Dictionary
/// </summary>
/// <param name="context">Active HTTP Context</param>
/// <param name="hostName">Host name connected to</param>
/// <param name="luName">LUName being disconnected</param>
/// <param name="sessionInfo">Additional Session Information</param>
/// <returns></returns>
static public bool Disconnecting(HttpContext context, string luName, string hostName, Dictionary<string, string> sessionInfo)
{
TimeSpan span = TimeSpan.MinValue;
DateTime startTime = DateTime.Now;
try
{
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Path.Combine(FVTermFolder, "Disconnecting.txt"), true))
{
sw.WriteLine(String.Format("User:{0}/{1}, HostName:{2}, luName:{3}, Duration In Seconds:{4}", sessionInfo["SessionOwner"],
hostName, luName, sessionInfo["ConnectedSeconds"]));
}
}
catch (System.Exception)
{ }
return true;
}
The above sample demonstrates logging each user session disconnect.