Deleting a file via Global.asa when session ends 
Author Message
 Deleting a file via Global.asa when session ends

Hi--

This is regarding ASP code in the Global.asa file.

I create a Session variable in the Session_OnStart sub-
routine, as follows:
Session("massGeneratedLetter")
= "/views/massGeneratedLetters/Letters_" & Session
("UserID") & ".rtf"

This is a pointer to a filename.  The filename is specific
to the username, due to the previously created Session
("UserID") variable in the filename.  This file is created
by a user when she performs a certain action within the
website.  

When the session ends, I'm trying to delete the file
created by the user, with the following code:
Sub Session_OnEnd

        Dim fs
        Set fs = CreateObject("Scripting.FileSystemObject")
        Dim tmp
        tmp = Session("massGeneratedLetter")

        fs.DeleteFile(tmp)

End Sub

However, I tested it out and didn't see the file deleted
from the directory.  What does it mean that a session has
ended?  Is the above code correct to delete files created
by different users, depending on their sessions?

Thanks in advance,
- JPA



Mon, 24 May 2004 04:41:25 GMT  
 Deleting a file via Global.asa when session ends
fs.DeleteFile Server.MapPath(tmp)

--
Michael Harris
Microsoft.MVP.Scripting

Quote:

> Hi--

> This is regarding ASP code in the Global.asa file.

> I create a Session variable in the Session_OnStart sub-
> routine, as follows:
> Session("massGeneratedLetter")
> = "/views/massGeneratedLetters/Letters_" & Session
> ("UserID") & ".rtf"

> This is a pointer to a filename.  The filename is specific
> to the username, due to the previously created Session
> ("UserID") variable in the filename.  This file is created
> by a user when she performs a certain action within the
> website.  

> When the session ends, I'm trying to delete the file
> created by the user, with the following code:
> Sub Session_OnEnd

> Dim fs
> Set fs = CreateObject("Scripting.FileSystemObject")
> Dim tmp
> tmp = Session("massGeneratedLetter")

> fs.DeleteFile(tmp)

> End Sub

> However, I tested it out and didn't see the file deleted
> from the directory.  What does it mean that a session has
> ended?  Is the above code correct to delete files created
> by different users, depending on their sessions?

> Thanks in advance,
> - JPA



Mon, 24 May 2004 11:19:36 GMT  
 Deleting a file via Global.asa when session ends
Thanks, Michael.

What does it mean that a session has ended?  If I close
all the browser windows associated with the application,
will that end the session?  (I tried that but my file
didn't get deleted from its location, despite the change
to fs.DeleteFile Server.MapPath(tmp) ).  

Do I need to call the function Session_OnEnd() somewhere?  
If so, where?

Thanks a lot!
- JPA

Quote:
>-----Original Message-----
>fs.DeleteFile Server.MapPath(tmp)

>--
>Michael Harris
>Microsoft.MVP.Scripting




Quote:
>> Hi--

>> This is regarding ASP code in the Global.asa file.

>> I create a Session variable in the Session_OnStart sub-
>> routine, as follows:
>> Session("massGeneratedLetter")
>> = "/views/massGeneratedLetters/Letters_" & Session
>> ("UserID") & ".rtf"

>> This is a pointer to a filename.  The filename is
specific
>> to the username, due to the previously created Session
>> ("UserID") variable in the filename.  This file is
created
>> by a user when she performs a certain action within the
>> website.  

>> When the session ends, I'm trying to delete the file
>> created by the user, with the following code:
>> Sub Session_OnEnd

>> Dim fs
>> Set fs = CreateObject("Scripting.FileSystemObject")
>> Dim tmp
>> tmp = Session("massGeneratedLetter")

>> fs.DeleteFile(tmp)

>> End Sub

>> However, I tested it out and didn't see the file
deleted
>> from the directory.  What does it mean that a session
has
>> ended?  Is the above code correct to delete files
created
>> by different users, depending on their sessions?

>> Thanks in advance,
>> - JPA

>.



Mon, 24 May 2004 22:32:24 GMT  
 Deleting a file via Global.asa when session ends
ACtually Jyotsna
That's exactly what I am trying to figure out when does
that stupid method session_onend() runs :-)
Wish me luck
I think when we can figure out when that runs other code
is pretty much file.

Quote:
>-----Original Message-----
>Hi--

>This is regarding ASP code in the Global.asa file.

>I create a Session variable in the Session_OnStart sub-
>routine, as follows:
>Session("massGeneratedLetter")
>= "/views/massGeneratedLetters/Letters_" & Session
>("UserID") & ".rtf"

>This is a pointer to a filename.  The filename is
specific
>to the username, due to the previously created Session
>("UserID") variable in the filename.  This file is
created
>by a user when she performs a certain action within the
>website.  

>When the session ends, I'm trying to delete the file
>created by the user, with the following code:
>Sub Session_OnEnd

>    Dim fs
>    Set fs = CreateObject("Scripting.FileSystemObject")
>    Dim tmp
>    tmp = Session("massGeneratedLetter")

>    fs.DeleteFile(tmp)

>End Sub

>However, I tested it out and didn't see the file deleted
>from the directory.  What does it mean that a session has
>ended?  Is the above code correct to delete files created
>by different users, depending on their sessions?

>Thanks in advance,
>- JPA
>.



Tue, 25 May 2004 03:47:55 GMT  
 Deleting a file via Global.asa when session ends
The session ends from the server's perspective when it times out, by default after 15 minutes of no client access.  Once the user closes the browser, the sessionid cookie is gone (it's kept in memory only), so if they come back to the site even within the timeout period, they start a completely new session.  

What you are doing isn't session specific, only user specific.  You will have problems if the user closes the browser and starts it again and comes back within 15 minutes.  The prior session will timeout and delete the file while the new session is still active. I've done the same kind of thing you are doing with temp files created for the user that use the session.sessionid as part of the temp file name.  

--
Michael Harris
Microsoft.MVP.Scripting

Quote:

> Thanks, Michael.

> What does it mean that a session has ended?  If I close
> all the browser windows associated with the application,
> will that end the session?  (I tried that but my file
> didn't get deleted from its location, despite the change
> to fs.DeleteFile Server.MapPath(tmp) ).  

> Do I need to call the function Session_OnEnd() somewhere?  
> If so, where?

> Thanks a lot!
> - JPA

> >-----Original Message-----
> >fs.DeleteFile Server.MapPath(tmp)

> >--
> >Michael Harris
> >Microsoft.MVP.Scripting



> >> Hi--

> >> This is regarding ASP code in the Global.asa file.

> >> I create a Session variable in the Session_OnStart sub-
> >> routine, as follows:
> >> Session("massGeneratedLetter")
> >> = "/views/massGeneratedLetters/Letters_" & Session
> >> ("UserID") & ".rtf"

> >> This is a pointer to a filename.  The filename is
> specific
> >> to the username, due to the previously created Session
> >> ("UserID") variable in the filename.  This file is
> created
> >> by a user when she performs a certain action within the
> >> website.  

> >> When the session ends, I'm trying to delete the file
> >> created by the user, with the following code:
> >> Sub Session_OnEnd

> >> Dim fs
> >> Set fs = CreateObject("Scripting.FileSystemObject")
> >> Dim tmp
> >> tmp = Session("massGeneratedLetter")

> >> fs.DeleteFile(tmp)

> >> End Sub

> >> However, I tested it out and didn't see the file
> deleted
> >> from the directory.  What does it mean that a session
> has
> >> ended?  Is the above code correct to delete files
> created
> >> by different users, depending on their sessions?

> >> Thanks in advance,
> >> - JPA

> >.



Tue, 25 May 2004 08:18:40 GMT  
 Deleting a file via Global.asa when session ends
Thanks for the details, Michael.

I see your point re: the conflict if a user ends one
session and starts another, the previous session should
delete the file when it times out, even though the user
has started  a new session.  Perhaps I should add the
Session.SessionID variable to the filename also.

However, the problem I am seeing is that the file *never*
gets deleted!  It's as if the Session_OnEnd method was not
being called at all.  Even if I just start a session,
create the file, and then quit the session, not starting
another one for the next hour, the file remains.  
Therefore I also tried a simple test of creating a
recordset in the Session_OnEnd method, which inserts a
test value into a database table - but this value doesn't
get inserted when I quit the session.  Is there something
else that needs to be done here?  Here's my Session_OnEnd
method (with the test recordset):
Sub Session_OnEnd      
        Dim fs
        Set fs = Server.CreateObject
("Scripting.FileSystemObject")
        Dim tmp
        Set tmp = Session("massGeneratedLetter")

        Set cmdTmp = Server.CreateObject("ADODB.Command")
        Set rsTmp = Server.CreateObject("ADODB.Recordset")
        Set cmdTmp.ActiveConnection = DBConn
        rsTmp.Close
        Set rsTmp.Source = cmdTmp
        cmdTmp.CommandType = 1
        cmdTmp.CommandTimeout = 60
        cmdTmp.CommandText = "INSERT INTO Tmp_SessionTest
(tmpVar)VALUES ('success!')"

        rsTmp.CacheSize = 10
        rsTmp.CursorType = 3
        rsTmp.CursorLocation = 3
        rsTmp.LockType = 3
        rsTmp.Open
        rsTmp.Requery

        fs.DeleteFile Server.MapPath(tmp)
End Sub

Do I need to call the Session_OnEnd method somewhere in
order for it to execute?

Thanks much!
- JPA

Quote:
>-----Original Message-----
>The session ends from the server's perspective when it

times out, by default after 15 minutes of no client
access.  Once the user closes the browser, the sessionid
cookie is gone (it's kept in memory only), so if they come
back to the site even within the timeout period, they
start a completely new session.  
Quote:

>What you are doing isn't session specific, only user

specific.  You will have problems if the user closes the
browser and starts it again and comes back within 15
minutes.  The prior session will timeout and delete the
file while the new session is still active. I've done the
same kind of thing you are doing with temp files created
for the user that use the session.sessionid as part of the
temp file name.  
Quote:

>--
>Michael Harris
>Microsoft.MVP.Scripting




Quote:
>> Thanks, Michael.

>> What does it mean that a session has ended?  If I close
>> all the browser windows associated with the
application,
>> will that end the session?  (I tried that but my file
>> didn't get deleted from its location, despite the
change
>> to fs.DeleteFile Server.MapPath(tmp) ).  

>> Do I need to call the function Session_OnEnd()
somewhere?  
>> If so, where?

>> Thanks a lot!
>> - JPA

>> >-----Original Message-----
>> >fs.DeleteFile Server.MapPath(tmp)

>> >--
>> >Michael Harris
>> >Microsoft.MVP.Scripting



>> >> Hi--

>> >> This is regarding ASP code in the Global.asa file.

>> >> I create a Session variable in the Session_OnStart
sub-
>> >> routine, as follows:
>> >> Session("massGeneratedLetter")
>> >> = "/views/massGeneratedLetters/Letters_" & Session
>> >> ("UserID") & ".rtf"

>> >> This is a pointer to a filename.  The filename is
>> specific
>> >> to the username, due to the previously created
Session
>> >> ("UserID") variable in the filename.  This file is
>> created
>> >> by a user when she performs a certain action within
the
>> >> website.  

>> >> When the session ends, I'm trying to delete the file
>> >> created by the user, with the following code:
>> >> Sub Session_OnEnd

>> >> Dim fs
>> >> Set fs = CreateObject("Scripting.FileSystemObject")
>> >> Dim tmp
>> >> tmp = Session("massGeneratedLetter")

>> >> fs.DeleteFile(tmp)

>> >> End Sub

>> >> However, I tested it out and didn't see the file
>> deleted
>> >> from the directory.  What does it mean that a
session
>> has
>> >> ended?  Is the above code correct to delete files
>> created
>> >> by different users, depending on their sessions?

>> >> Thanks in advance,
>> >> - JPA

>> >.

>.



Tue, 25 May 2004 21:33:48 GMT  
 Deleting a file via Global.asa when session ends
I found the following article regarding a bug with
Session_OnEnd: http://support.microsoft.com/default.aspx?
scid=kb;EN-US;q277329

However, the article says that this bug is relevant to
accessing network resources... in my case, I am trying to
delete files that are locally on the web server - so does
this situation apply?  Please help!

Thanks,
- JPA

Quote:
>-----Original Message-----
>Hi--

>This is regarding ASP code in the Global.asa file.

>I create a Session variable in the Session_OnStart sub-
>routine, as follows:
>Session("massGeneratedLetter")
>= "/views/massGeneratedLetters/Letters_" & Session
>("UserID") & ".rtf"

>This is a pointer to a filename.  The filename is
specific
>to the username, due to the previously created Session
>("UserID") variable in the filename.  This file is
created
>by a user when she performs a certain action within the
>website.  

>When the session ends, I'm trying to delete the file
>created by the user, with the following code:
>Sub Session_OnEnd

>    Dim fs
>    Set fs = CreateObject("Scripting.FileSystemObject")
>    Dim tmp
>    tmp = Session("massGeneratedLetter")

>    fs.DeleteFile(tmp)

>End Sub

>However, I tested it out and didn't see the file deleted
>from the directory.  What does it mean that a session has
>ended?  Is the above code correct to delete files created
>by different users, depending on their sessions?

>Thanks in advance,
>- JPA
>.



Wed, 26 May 2004 00:13:28 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Delete Directory in Session_OnEnd in GLOBAL.ASA

2. SESSION ONEND & global.asa

3. Global ASA and Session Variables

4. (asp) declaring session arrays in global.asa

5. include files in global.asa file?

6. global.asa and global.asax ?

7. Global.asa Include files

8. Global.asa file

9. Error in my global.asa file!

10. newbie question (Global.ASA file)

11. Using Global.asa File for Password Protection

12. Known bug with Session_OnEnd method in Global.asa file

 

 
Powered by phpBB® Forum Software