473,396 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2559
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: MostlyH2O | last post by:
Hi Folks, I'm having a hard time getting my Session_OnEnd event to fire in my global.asa. Here's what I have: <SCRIPT LANGUAGE=VBSCRIPT RUNAT=Server> SUB Session_OnStart Session.TimeOut =...
3
by: Tom Bates | last post by:
I can successfully delete files using fso.DeleteFile when in an ASP script. But in Session_OnEnd, where I'd *really* like to clean up files, it appears that DeleteFile doesn't work. I've tried...
3
by: cab | last post by:
i have the following code in the "Sub Session_OnEnd" routine that does not seem to run..... Sub Session_OnEnd strConnect = "Driver={SQL Server};Server=SERVER;Database=database; User...
24
by: Nancy Drew | last post by:
hi all i'm trying to keep users from being able to login to a site twice at the same time. everytime a user does a login, i stick their userID into an application scoped array. if they try to...
4
by: HolaGoogle | last post by:
hi there, i've 2 questions for you guys.... 1: is there any way to "force" a session_onend(), session timeout or at least call my logout method when a user leaves the application window without...
3
by: Phil Lamey | last post by:
Hi All, I have the following code but for some reason I cannot get the Session_OnEnd event to fire. I am trying to limit the amount of connections a browser session can have. Where the...
11
by: andrea azzini | last post by:
I've got an ASP3 (IIS6) site, in which some scripts need to generate temporary files in order to work. Now, the fact is: I would like those temporary files to be deleted when a user's session ends...
4
by: anand | last post by:
In my website i want to trace the event when user log off from the site by closing the explorer so i am unable to run any server side program at that time and my session_onend event also not...
1
by: Andy Kasotia | last post by:
My Session_OnStart works but Session_OnEnd does not work. Here's the code...can anyone tell me what's wrong with my code or if anything else on the server that needs to be changed. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.