Session_Start/Session_End

M

Mufasa

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
 
G

Guest

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.
 
H

Hans Kesting

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
 
G

Guest

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 said:
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
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top