Rick,
I have spent couple of hours playing with the session to see what the confusion is about... Here is what I found. Please feel free to correct me if you found something wrong
RickNZ:1. An explicit call by the server to Session.Abandon(). That will delete the session cookie and call Session_End().
Session cookie is not really removed from the browser. Session is simply ended at the server and Session_End is called and the Session ID may be reused for the subsquent request from the same browser instance.. Here is a microsoft KB article regarding this
http://support.microsoft.com/kb/899918
RickNZ:2. No action by the server; the session just ages past its intended life time. Session_End() won't be called in that case.
Session_End is called at every instance in the "InProc" mode. You might see weird behavior when you are debugging in the VS.NET, but in normal execution Session_End is called everytime session ends, either its by calling Session.Abandon or automatic session time out
I used the following code to check this behavior
void Session_Start(object sender, EventArgs e)
{
StreamWriter SW;
SW = File.AppendText(@"D:\test.txt");
SW.WriteLine("Session ID: " + Session.SessionID);
SW.WriteLine("Session Started at: " + DateTime.Now.ToString());
SW.Write("\n");
SW.Close();
}
void Session_End(object sender, EventArgs e)
{
StreamWriter SW;
SW = File.AppendText(@"D:\test.txt");
SW.WriteLine("Session ID: " + Session.SessionID);
SW.WriteLine("Session Expired at: " + DateTime.Now.ToString());
SW.Write("\n");
SW.Close();
}
RickNZ:
Until you store
something into the Session dictionary for a given user, the session
HttpModule will not set a session cookie. Until the session cookie is
set, the session HttpModule will create a new session for each request;
that includes a new session ID.
This is true, unless you have a handler defined in the Global.asax page for Session_Start or Session_End. If these handlers are not defined a new Session ID is generated for every request, when there is nothing stored in the Session bag
I do not have a proper reasoning why this behavior. Please explain if you find anything