473,320 Members | 1,535 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,320 software developers and data experts.

Session_Start/Session_End

I have code in my session_start to create a temp directory for the session.
On session_end it is supposed to delete the directory but doesn't seem to be
firing.

I've enclosed the code below.

Can anybody give me any suggestions as to why Session_End seems to not be
being fired?

TIA - J.
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
'User only allowed 3 login attempts
Session("Num_of_Tries") = 3
Session("LoginCount") = 0

'Track if user is logged in or not
Session("Logged_IN") = "No"

Try
Dim lsDefaultDir As String = Server.MapPath("\")
lsDefaultDir = lsDefaultDir + "Temp"
Dim lsTempDir As String = lsDefaultDir + "\" +
Session.SessionID.ToString()

If (Not Directory.Exists(lsTempDir)) Then
Directory.CreateDirectory(lsTempDir)
End If
Catch ex As Exception
Dim lobjEMail As Marlin.Utilities.MarlinErrorHandler = New
Marlin.Utilities.MarlinErrorHandler
lobjEMail.ProcessError(ex, "Global.asax.vb_Session_Start",
"Global.asax.vb", False)
Dim lstemp As String
lstemp = ex.Message
End Try
End Sub


Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Dim lsDefaultDir As String = Server.MapPath("\")
lsDefaultDir = lsDefaultDir + "Temp"
Dim lsTempDir As String = lsDefaultDir + "\" +
Session.SessionID.ToString()

If (Directory.Exists(lsTempDir)) Then
Directory.Delete(lsTempDir)
End If
End Sub
Sep 6 '07 #1
3 5740
Session_End only fires for InProc Session mode, and it fires on the server.
This is independent of what a user may do such as close their browser or go
visit another site.
If you are having trouble getting the sessionID when Session_End fires, put
in some code that tries to get it from the actual cookie:

string szCookieHeader = Request.Headers["Cookie"];
if ((null != szCookieHeader) &&
(szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
.... etc.
--
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Mufasa" wrote:
I have code in my session_start to create a temp directory for the session.
On session_end it is supposed to delete the directory but doesn't seem to be
firing.

I've enclosed the code below.

Can anybody give me any suggestions as to why Session_End seems to not be
being fired?

TIA - J.
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
'User only allowed 3 login attempts
Session("Num_of_Tries") = 3
Session("LoginCount") = 0

'Track if user is logged in or not
Session("Logged_IN") = "No"

Try
Dim lsDefaultDir As String = Server.MapPath("\")
lsDefaultDir = lsDefaultDir + "Temp"
Dim lsTempDir As String = lsDefaultDir + "\" +
Session.SessionID.ToString()

If (Not Directory.Exists(lsTempDir)) Then
Directory.CreateDirectory(lsTempDir)
End If
Catch ex As Exception
Dim lobjEMail As Marlin.Utilities.MarlinErrorHandler = New
Marlin.Utilities.MarlinErrorHandler
lobjEMail.ProcessError(ex, "Global.asax.vb_Session_Start",
"Global.asax.vb", False)
Dim lstemp As String
lstemp = ex.Message
End Try
End Sub


Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Dim lsDefaultDir As String = Server.MapPath("\")
lsDefaultDir = lsDefaultDir + "Temp"
Dim lsTempDir As String = lsDefaultDir + "\" +
Session.SessionID.ToString()

If (Directory.Exists(lsTempDir)) Then
Directory.Delete(lsTempDir)
End If
End Sub
Sep 6 '07 #2
Session_End only fires for InProc Session mode, and it fires on the
server. This is independent of what a user may do such as close their
browser or go visit another site. If you are having trouble getting
the sessionID when Session_End fires, put in some code that tries to
get it from the actual cookie:

string szCookieHeader = Request.Headers["Cookie"];
if ((null != szCookieHeader) &&
(szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
... etc.
eh, what Request would that be on session_end??
There *is* no request, hasn't been for some time, that's why the session
ends!

Hans Kesting
Sep 6 '07 #3
Absolutely right. Thanks for reminding me. Session_End fires on the server,
it is independent of any Request. Probably one of the most misunderstood
little tidbits of ASP.NET.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Hans Kesting" wrote:
Session_End only fires for InProc Session mode, and it fires on the
server. This is independent of what a user may do such as close their
browser or go visit another site. If you are having trouble getting
the sessionID when Session_End fires, put in some code that tries to
get it from the actual cookie:

string szCookieHeader = Request.Headers["Cookie"];
if ((null != szCookieHeader) &&
(szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
... etc.

eh, what Request would that be on session_end??
There *is* no request, hasn't been for some time, that's why the session
ends!

Hans Kesting
Sep 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve Donnelly | last post by:
I have an HttpModule that gets the SessionStateModule and registers for the Start and End events. Global receives both Start and End events (both timeout and when Session.Abandon() is called),...
3
by: Guadala Harry | last post by:
Just wondering if Session_End *always fires* for every Session. I know that IIS times out sessions after a default 20 min (unless changed) and there's no way to know when a user actually closed a...
4
by: Kim Bach Petersen | last post by:
I would like to record user behavior data stored in session variables. Since the data is modified throughout each session it seemed obvious to store the data when the session terminates - using...
7
by: Henry | last post by:
I have a question on session_end. I'm trying to log into my database when the session times out, it will store user info into a table. When I got step into a line where I was trying to open...
7
by: Bruno | last post by:
We are attempting to automatically log users off from the Session_End event in global.asax and set some values on session_start. It is not a critical task, more of a housekeeping task so that we...
8
by: Roger | last post by:
When I call the session.abandon() method, it calls the session_end event. When a user closes the browser or clicks the log off button, I can dispose of objects and abandon the session cleaning....
1
by: =?Utf-8?B?YnJlbnQ5NjA=?= | last post by:
Environment: ASP.NET 2.0, SQL Server 2005, C#, Visual Studio 2005 In my Session_End event, I am executing a stored procedure to update a database table that is used to log user sessions. When...
12
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I am trying to maintain a list of people who are currently "online" in SQL. I do this by adding a simple entry to a simple PeopleOnline table whenever someone logs in to my site. If they...
5
by: greg | last post by:
Written in Asp.Net 2.0 The session_start fires on Development server running withing Visual Studio 2005 and also if access web site via localhost on development machine. But if copy to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.