469,645 Members | 1,201 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Session_OnEnd is not being called

Hi,

Since I went ASP.NET with my global.asa (making it a global.asax) the
application events are called just fine as well as the Session_OnStart event
but the Session_OnEnd event is not. What is wrong? My global.asax looks like
this:

<%@ Application src="app.cs" Inherits="mwte.App" %>
This is my code behind file (app.cs):

namespace mwte
{
using System;
using System.IO;
using System.Web;
using System.Xml;
using System.Web.SessionState;

public class App : System.Web.HttpApplication
{
public void SaveSessionInfo()
{
}

// application event handlers
protected void Application_OnStart(Object Sender, EventArgs e)
{
}

protected void Application_OnEnd(Object Sender, EventArgs e)
{
}

// other application event handlers left out for brevity

// session event handlers
protected void Session_Start(Object sender, EventArgs e)
{
}

protected void Session_End(Object sender, EventArgs e)
{
}

}
}
The documentation says that for the End event to occur, session state mode
must be InProc. It should be, in my web.config it says:

<configuration>
<system.web>
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424" stateNetworkTimeout="10"
sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI"
cookieless="false" timeout="20" />
</system.web>
</configuration>
Any insightswould be appreciated.

Martin.
Nov 18 '05 #1
6 2282
Hi,

did you wait 20 sec. after the last user request as it defined in your
web.config?

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2
Natty,
did you wait 20 sec. after the last user request as it defined in your

web.config?

No, I assumed that 20 was the default 20 minutes timeout for a session. And
when I call Session.Abandon, I expect Session_OnEnd to kick in immediately
(this is how it worked in classic ASP).

The strange thing is that I did get 2 or 3 Session_OnEnd events at
unsuspected times after I posted the problem. But when I invoke the Abandom
method, wait for well over 20 minutes, than look at the log to see if
Session_OnEnd ever occured it appears it didn't. It seems to behave very
irrational.
I looked at your web log the other day and I found it quite informative yet
could not keep up reading it because of the bad English that was kicking my
mind around two or three times every sentense. You should have your articles
edited by someone more comfortable with the English language and you will
have more readers.

Regards, Martin.
Nov 18 '05 #3
The session_end event is normally called after the server has not gotten any
page requests from the user for 20 minutes (default, configurable in your
web.config).
The Session_End won't fire in a few circumstances, such as when you
end the session prematurely (i.e. pressing the stop button in VS.NET) or if
you aren't using the standard InProc sessions.

Here's more details for you:
http://www.asp.net/Forums/ShowPost.a...=1&PostID=7504

--
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...
Hi,

Since I went ASP.NET with my global.asa (making it a global.asax) the
application events are called just fine as well as the Session_OnStart event but the Session_OnEnd event is not. What is wrong? My global.asax looks like this:

<%@ Application src="app.cs" Inherits="mwte.App" %>
This is my code behind file (app.cs):

namespace mwte
{
using System;
using System.IO;
using System.Web;
using System.Xml;
using System.Web.SessionState;

public class App : System.Web.HttpApplication
{
public void SaveSessionInfo()
{
}

// application event handlers
protected void Application_OnStart(Object Sender, EventArgs e)
{
}

protected void Application_OnEnd(Object Sender, EventArgs e)
{
}

// other application event handlers left out for brevity

// session event handlers
protected void Session_Start(Object sender, EventArgs e)
{
}

protected void Session_End(Object sender, EventArgs e)
{
}

}
}
The documentation says that for the End event to occur, session state mode
must be InProc. It should be, in my web.config it says:

<configuration>
<system.web>
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424" stateNetworkTimeout="10"
sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI"
cookieless="false" timeout="20" />
</system.web>
</configuration>
Any insightswould be appreciated.

Martin.

Nov 18 '05 #4
> 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.
Nov 18 '05 #5
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.

Nov 18 '05 #6
> 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.


Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by cab | last post: by
3 posts views Thread by Phil Lamey | last post: by
11 posts views Thread by andrea azzini | last post: by
4 posts views Thread by anand | last post: by
1 post views Thread by Andy Kasotia | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.