> Session.Abandon doesn't invoke Session_End. That is by design.
No, that's not entirely correct. Session.Abandon may call session_end if the
mode is set to inproc. It's easy to draw the wrong conclusions because if
you build a page, place session.abandon() as the first line and put a break
point in session_end it will not fire. This slide of hand causes one to
conclude, rather erroneously, that session_end isn't fired when session
abandon is invoked.
The Abandon method will destroy the session by sending a new session id
cookie with an old expiration date. Then, abandon destroys the dictionary
associated with the session. Whether session_end event fires next is
entirely dependent on the state of the session id. Here is how they are
related. If the session id is regenerated, session end event fires. If the
session id is not regenerated, session end fails to fire. So in one case,
calling session abandon will invoke the session end event.
Session ID regeneration is peculiar (complicated) and optimized to support
the stateserver architecture. A new session id is regenerated if the
dictionary associated with the session has been written to at least once AND
at least one request has been completed successfully otherwise session id is
maintained even though the request may have terminated, and abandon has been
invoked. In that case, the existing session id is reused until the browser
is closed even though a new page is requested. With a new session id,
session end event fires.
In the OP's case, if the dictionary object isn't being written to OR a
request has not been completed successfully and abandon is called, session
end event will never fire because, as explained above, the same session id
is being recycled. To prove that this is the case, you will need to set up a
test case where you write to session in the page load. This satisfies one
condition. To satisfy the other condition, drop a button on your page and in
its event handler, call
session abandon. The successfull request will be the initial page load. With
both conditions satisfied, session end will fire.
Here is the complete test case example
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
//removing the next line of code causes the
//condition to only be partially satisified
Session["test"] = "test";
//session end will not be called if the next line is uncommented
//because the conditions are only partially satisified
//Session.Abandon();
}
private void Button1_Click(object sender, System.EventArgs e)
{
//session end will be called here because both
//mutually inclusive events satisfy the condtion
Session.Abandon();
}
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:u4**************@TK2MSFTNGP11.phx.gbl...
Session.Abandon doesn't invoke Session_End. That is by design. I'm not
saying that's a good or bad design, that's just how they made it. But it
shouldn't matter much; you can move your Session_End code into a separate
procedure and then call that procedure from Session_End and wherever you
call Session.Abandon.
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
"Martin" <du***@somewhere.nl> wrote in message
news:3f**********************@dreader7.news.xs4all .nl... Here's more details for you:
http://www.asp.net/Forums/ShowPost.a...=1&PostID=7504
Hmm... Good source! It still doesn't all make sense to me yet what I am
experiencing. The time-out session end may have an access rights problem
with the log file though because it is called from a different thread as
it says in the FAQ. That would explain that part. But why doesn't
Session.Abandon() trigger Session_OnEnd ? It should.
Thanks for the link.
Martin.