Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Session_OnEnd.....Any ideas?

Status
Not open for further replies.

BigM

Programmer
Aug 30, 2000
39
0
0
GB
Hi,

I have the following global.asa which should delete any files created during the current session. The file names when created contain the SessionID so each user has their own copy of the files to work on. However this doesnt seem to be working...the files are not deleted when the session times out.....any ideas?

------------------------------------------------------------
<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Session_OnEnd
Dim strAppPath, strFilePath, strFileName
Dim objFSO, objFile
Dim arrFiles(2)

Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

strAppPath = Request.ServerVariables(&quot;APPL_PHYSICAL_PATH&quot;)
strFilePath = strAppPath & &quot;Config\&quot; & Session(&quot;EnvRoot&quot;)

arrFiles(0) = strFilePath & &quot;\&quot; & Session.SessionID & &quot;BV.tpl&quot;
arrFiles(1) = strFilePath & &quot;\&quot; & Session.SessionID & &quot;IM.tpl&quot;
arrFiles(2) = strFilePath & &quot;\&quot; & Session.SessionID & &quot;WB.tpl&quot;

For Each strFileName in arrFiles
response.write &quot;File &quot; & strFileName
If (objFSO.FileExists(strFileName)) Then
Set objFile = objFSO.GetFile(strFileName)
objFile.Delete
End If
Next

Set objFSO = Nothing
Set objFile = Nothing
End Sub

</SCRIPT>
 
I've had the same problem regarding keeping track of users currently online. It seemed to me that when I would force a Session.Abandon it would execute the On_End event flawlessly. If a session were to timeout, sometimes it would, sometimes it wouldn't. I tried EVERYTHING and couldn't get that On_End event to fire regularly on session timeouts. I talked to other ASP developers that had a hard time with the On_End event and they all finally gave up as well. I'm attributing it to a bug that fails to fire this event. I finally made my own work around by basically setting up my own 'Ending' event but it was un necessary if the On_End event fired properly. I hope someone else might be able to give more insight on this and if it is a bug, I hope it's fixed in Win 2k's version of ASP. I have not been able to develop anything on that platform as of yet however. Any more info on this would be GREATLY appreciated. Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Hi Ed,

If that is the case its a pretty fundemental flaw. What a complete p*sser!!!!

I will have to think of some other way of housekeeping as there could be many of these files left lying round on the web server.

Maybe I could check the create date on files and if its more than a day old delete it.
 
I saw on another discussion that Session_OnEnd is buggy and will not always be fired (and not, even in IIS5 this is fixed flawlessly).

urthermore, it may be that the Request or Response object Fisn't even available. You are only allowed to use the Session and Application variables in Session_OnEnd.

Hope this helps... Yours,

Rob.
 
I had a major problem with Session_OnEnd the other day and I came to the conclusion that the Response and Request objects are not available for Session_OnEnd and neither is the MapPath function.

My script was to connect to a DB to perform some tidy up operation. As the DB was in the same place, I stored the path as a string in the Application_OnStart event and merely referenced it in Session_OnEnd. A bit of a bodge, but it fixed hours of hair pulling!!
 
You could log the sessionID in a separate table and delete from that table on session end also. You could track when the session was created and delete any session that is over a certain amount of time old. Not perfect, but it could work. If you were really into it, you could update the table on each new page call so that you could see when the last action occurred and delete files that have been inactive for a certain period of time. Extremely tedious, but doable...
 
I ran into a simular problem. I solved it by going backwards. When a user fires off your global.asa the very first thing you do is have it check for any files with the name sturcture that you are using and delete anything that is X time old. The trick is to decide how old somthing is before it is definetly not being used. I ended up going with one day just to be on the safe side. That is 24 hrs not the date. That way if you have people on just before midnight and another just after you wont be hosing them.

Hope that helps
Roj
 
Hi !


I also faced this problem, but was able to find a solution on IIS 5.0 .

Step 1. Pick the Path in session variable when session_onstart is fired, this will be used in the session_onend, as in session_onend, you cannot use server.mappath while in session_onstart you can do so.

session(&quot;se_filePath&quot;)= Server.MapPath(&quot;\PSQDB_ASP\AllExcel&quot;)

Stepl 2. Now in your session_onend do the following :

filePath= session(&quot;se_filePath&quot;) & &quot;\*&quot; & cstr(session.SessionID) & &quot;.xls&quot;
Set fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
fs.DeleteFile filePath


It works perfectly fine, only thing you need to be sure is that the file remains on the server 30 sec more than what time you have specified in the session timeout.

You don't need to use session.abandon

Try it..
Vikas
 
I am using Windows 2000 w/ IIS 5 and the OnEnd works great. I am only updating a db, but the filesystem should work. Copy and paste that script into a test file on the root of your website, and execute it to see if it works there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top