session question

  • Thread starter Thread starter anonmous
  • Start date Start date
A

anonmous

Hello,

I am creating a pdf via some code. Now when the pdf is
created, I assign the filename to a session variable and
open a new window with the pdf. Now when the user closes
the pdf window, I would like to delete the file. I was
thinking to check for the session variable in the
global.asax.vb in the session_end. However when I close
the pdf the session_end is never called. Is there any way
to do that?

Thanks in advance
 
Session_End is called (by default) 20 minutes after the user's last page
request.
It has nothing to do with when then user closes their browser window(s).
Therefore your code probably works, just not as quickly as you'd thought it
would.
 
Thanks Steve,

now I am wondering if it makes sense to delete the file
in Session_End. Isnt there a way to detect if the browser
was closed? I would like to delete the file immediately
when the browser is closed.

Thanks
 
Steve,

I have set the session timeout to 2 mins, however my
files dont get deleted. I tried the code in my webform and
it deleted the file. Here is my web.config session tag:

<sessionState mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data
source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="2"/>

Here is the code I used:

Sub Session_End(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when the session ends

' Do we have any PDF created?
If Not Session("PDFReportFileName") Is Nothing Then
Dim arFileNames As ArrayList = Session
("PDFReportFileName")
Dim iFile As Integer = 0
For iFile = 0 To arFileNames.Count - 1
Dim strFileName As String = arFileNames
(iFile)
System.IO.File.Delete(Server.MapPath
(strFileName))
Next
End If
End Sub


Thanks for your help
 
Back
Top