473,769 Members | 4,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sess ionState;

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

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

protected void Application_OnE nd(Object Sender, EventArgs e)
{
}

// other application event handlers left out for brevity

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

protected void Session_End(Obj ect 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:

<configuratio n>
<system.web>
<sessionState mode="InProc"
stateConnection String="tcpip=1 27.0.0.1:42424" stateNetworkTim eout="10"
sqlConnectionSt ring="data source=127.0.0. 1;Integrated Security=SSPI"
cookieless="fal se" timeout="20" />
</system.web>
</configuration>
Any insightswould be appreciated.

Martin.
Nov 18 '05 #1
6 2597
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***@somewher e.nl> wrote in message
news:3f******** *************@d reader7.news.xs 4all.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.Sess ionState;

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

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

protected void Application_OnE nd(Object Sender, EventArgs e)
{
}

// other application event handlers left out for brevity

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

protected void Session_End(Obj ect 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:

<configuratio n>
<system.web>
<sessionState mode="InProc"
stateConnection String="tcpip=1 27.0.0.1:42424" stateNetworkTim eout="10"
sqlConnectionSt ring="data source=127.0.0. 1;Integrated Security=SSPI"
cookieless="fal se" 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***@somewher e.nl> wrote in message
news:3f******** **************@ dreader7.news.x s4all.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.W ebControls.Butt on Button1;
private void Page_Load(objec t sender, System.EventArg s 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(o bject sender, System.EventArg s e)

{

//session end will be called here because both

//mutually inclusive events satisfy the condtion

Session.Abandon ();

}

"Steve C. Orr [MVP, MCSD]" <St***@Orr.ne t> wrote in message
news:u4******** ******@TK2MSFTN GP11.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***@somewher e.nl> wrote in message
news:3f******** **************@ dreader7.news.x s4all.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
9518
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 = 30 END SUB
3
3071
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 every combination I could think of. I've verified the filespecs I'm using by logging to a session log file. BTW, I found out the hard way that I can't reference Request.ServerVariables("APPL_PHYSICAL_PATH") from within Session_OnEnd. I had to copy...
3
3708
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 ID=xxxxxx;Pwd=xxxxxxx" Set objConnEnd = Server.CreateObject("ADODB.Connection") objConnEnd.Open strConnect
24
2463
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 login again, i bounce them to an error page. i use the session_onEnd sub within global.asa to remove their userID from the array at the end of their session, and this seems to work fine. however, if i just shut down the browser, the sub_onEnd...
4
4846
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 logging out? i.e: using the "X" in the right corner??? i'd like to reset to their default all my variables session?? is this possible??? 2: I've succesfully been able to ask the user to confirm whether he wants to extend his session before it...
3
515
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 application is a virtual directory. Any ideas? ------------
11
1840
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 (even though i've got infinite hosting space, i feel it somewhat impolite to leave GB's of useless temp files ;-) ). The Session_OnEnd event, though, seems to have some problems in doing this: 1. I found in MSDN that it couldn't call...
4
2581
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 working can any one tell me why the session_onend is not working. Thanx in advance
1
2140
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 Session_OnStart does create the folder for me with the SessionID as the folder name but Session_OnEnd does not delete that folder. Sub Session_OnStart Dim fso, f, DirToCreate 'Create a folder to store PDF Files Set fso =...
0
9586
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9990
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.