Session_End Event does not Fire.

G

Guest

All the documentation and discussion I have read indicate that the
Session_End is not supposed to fire unless you are in "inProc" Session state
mode, and then only on Session Timeout or at Session Abandon. I need the
event to fire at Session timeout in order to capture and store the Datetime
this occurs. However in the application I am writing, I have been unable
discern any indication that the event is firing. I have used break points,
writes to a database table, and writes to a text file to indicate when this
event fires. So far I have got nothing back. Yet I am able to verify the
the session has timed out. I have no indication of code failure, but nothing
happens when this event is supposed to fire. I really do need this so
information would be hugely appreciated.

ERJ MCSD MCDBA.
 
M

Marina

1) How are you sure that the session has indeed timed out?
2) Are you sure whatever code you have in Session_End isn't failing due to a
coding error?
3) Show us the code you have for your Session_End handler
 
H

Hans Kesting

OldProgrammer said:
All the documentation and discussion I have read indicate that the
Session_End is not supposed to fire unless you are in "inProc"
Session state mode, and then only on Session Timeout or at Session
Abandon. I need the event to fire at Session timeout in order to
capture and store the Datetime this occurs. However in the
application I am writing, I have been unable discern any indication
that the event is firing. I have used break points, writes to a
database table, and writes to a text file to indicate when this event
fires. So far I have got nothing back. Yet I am able to verify the
the session has timed out. I have no indication of code failure, but
nothing happens when this event is supposed to fire. I really do
need this so information would be hugely appreciated.

ERJ MCSD MCDBA.

You didn't specify, but when do you expect the Session_End to
occur? It's 20 minutes (by default) after the last request for this
session, not (as a lot of people assume) as soon as the browser
closes or the user "navigates away".

Hans Kesting
 
S

S. Justin Gengo

On top of that setting a breakpoint won't work. .NET connects to the web app
and listens to what it's doing in order to hit breakpoints. I believe that
will keep the session open.

I would set a write to a database/text file inside of the session end
handler, set your session time out to one minute (or less), compile the
application, connect to it manually outside of .NET
(http://localhost/yourappnamehere), and then step away for a water or soda.
When you come back the write should have occurred.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

The original question specifies
1. First tried to run needed code, then
2. Tried to write to dB table (hardcoding all connection strings and
values), then
3. writing to a plain vanilla text file.
4. I tried setting the web.config file to show time out value of 2 minutes.
Then when that did not work reset it back to 20 minutes and waited one hour.
All the seesion variables are gone and the application behaves as it is
supposed to when the session variables have been lost. The only thing that
did not happen was the write to the DB table then text file.

So I know the session did time out.
 
G

Guest

I tried setting the web.config file to show time out value of 2 minutes.
Then when that did not work reset it back to 20 minutes and waited one hour.
All the seesion variables are gone and the application behaves as it is
supposed to when the session variables have been lost. The only thing that
did not happen was the write to the DB table then text file.

So I know the session did time out.
 
G

Guest

1. The Web config was changed to show timeout at 2 minutes. When this did
not work, It was changed back to 20 minutes. Then I waited One hour before
clicking on the page. All Session variables were lost and all code behaved
as designed to do when session variables have been lost.

2. I used simplest possible database code, when I got no writes to the
table used below code in that event. In both cases, the code was run
elsewhere on a different page to verify that it was running with out errors
and it worked. I have not seen anything stating that ADO.Net or streamwriter
does work in Session_End. I am also using virtually same code in methods of
global.asax called from Session start event. All code runs properly without
issue.


Here is Session_end event code.

Dim swObject As StreamWriter 'Text Stream Object
Dim sPath As String

sPath = Server.MapPath("testClose.txt")

swObject = File.CreateText(sPath)
swObject.Write("closing" & CStr(Now()))
swObject = Nothing

ERJ MCSD MCDBA
 
M

Marina

You never actually close the file in your code. Which means it stays open,
and the next time someone else tries to write to it, they get an error.

Neither writing to disk or to the database are the simplest, because there
are so many potential things that could go wrong. With files you could have
a permissions issue, a file could be a readonly, etc. Also, if 2 users have
their sessions expire at the same time, this would cause an error as well.

To easily test Session_End createa variable somewhere that is Shared. Make
it an integer and initialize it to 0. In Session_Start increase it by 1. In
Session_End, decrease it by 1. Make sure to synchronize that code to avoid
threading issues.

Then, you should be able to open like 10 sessions, and then have a page that
writes out the value in that variable, and watch the number decrease as
sessions timeout. Of course, you should always have at least 1 session
alive - the one that you are checking the value with.
 
G

Guest

See above my post 9/19/05 1:25 PST

Here:

Dim swObject As StreamWriter 'Text Stream Object
Dim sPath As String

sPath = Server.MapPath("testClose.txt")

swObject = File.CreateText(sPath)
swObject.Write("closing" & CStr(Now()))
swObject = Nothing
 
G

Guest

I used one of our few MS support calls and got the answer direct from the
source.


ERJ MCSD MCDBA.
 
S

S. Justin Gengo

Hans,

At this point try putting a try catch around your OnSessionEnd Code.

Try
'---Your code here
Catch ex As Exception
Dim Test As String = "Place a breakpoint on this line and examine ""ex""
if the breakpoint is hit"
End Try

It's possible that your code is throwing an error before any breakpoint you
set is hit. This test may catch something.

Otherwise please show the code for your entire OnSessionEnd (Including all
the code even the declaration of the even handler.)


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top