Session_OnEnd does not DeleteFile()

A

andrea azzini

I've got an ASP3 (IIS6) site, in which some scripts need to generate
temporary files in order to work. Now, the fact is: I would like those
temporary files to be deleted when a user's session ends (even though i've
got infinite hosting space, i feel it somewhat impolite to leave GB's of
useless temp files ;-) ).

The Session_OnEnd event, though, seems to have some problems in doing this:

1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
problem, I hardcoded the base path and everything should have worked well.
2. The FileSystemObject.DeleteFile() method, though, seems to suffer from
the same problem: i get no error output on Session.Abandon() but the files
are still there.

Is there any workaround for this problem?
Thanks in advance
Andrea Azzini
 
B

Bob Barrows [MVP]

andrea said:
I've got an ASP3 (IIS6) site, in which some scripts need to generate
temporary files in order to work. Now, the fact is: I would like those
temporary files to be deleted when a user's session ends (even though
i've got infinite hosting space, i feel it somewhat impolite to leave
GB's of useless temp files ;-) ).

The Session_OnEnd event, though, seems to have some problems in doing
this:

1. I found in MSDN that it couldn't call Server.MapPath(). Not a big
problem, I hardcoded the base path and everything should have worked
well.
2. The FileSystemObject.DeleteFile() method, though, seems to suffer
from the same problem: i get no error output on Session.Abandon() but
the files are still there.

Is there any workaround for this problem?
Thanks in advance
Andrea Azzini

Your IWAM_machinename account needs Change permissions for the folder.
Bob Barrows
 
A

andrea azzini

ehp... not possible... i mean, have an hosting plan so i can't access the
server's system settings. But ASP scripts have full access permissions to
that specific folder.
 
B

Bob Barrows [MVP]

Session and Application events run under the IWAM account, not the IUSR.
There is no other solution. IWAM needs file-system permissions for that
folder.

Bob Barrows
 
A

andrea azzini

No way to get that. But I've found another solution... i'll use a BLOB in
the mysql database where i surely have all the access rights i need. Thanx
anyway.
 
R

Roland Hall

: No way to get that. But I've found another solution... i'll use a BLOB in
: the mysql database where i surely have all the access rights i need. Thanx
: anyway.

Can you say performance hit? I chose a different path for cleanup. I wrote
a routine the merchant runs once a day. It cleans up all temp files 3 days
or older, or whatever their retention setting is.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
A

andrea azzini

This sounds really interesting, i had not thought about it... but, is there
any way to have a script run at an aribitrary time or should i just put it
into another (frequently accessed) page and let it check whether it's time
to run or not?
Remember i am on hosting so i can't do more than edit the files in my site's
directory...
 
A

andrea azzini

This also clarifies some question i had wondered about the difference
between those two users on my testing server... thank you.
 
A

Aaron [SQL Server MVP]

This sounds really interesting, i had not thought about it... but, is there
any way to have a script run at an aribitrary time or should i just put it
into another (frequently accessed) page and let it check whether it's time
to run or not?

I think there are web-based cron-type services out there that will allow you
to schedule hits against your URLs from their remote servers. You can also
see http://www.aspfaq.com/2143
 
R

Roland Hall

in message
: This sounds really interesting, i had not thought about it... but, is
there
: any way to have a script run at an aribitrary time or should i just put it
: into another (frequently accessed) page and let it check whether it's time
: to run or not?
: Remember i am on hosting so i can't do more than edit the files in my
site's
: directory...

I didn't look at Aaron's link but if you cannot get it scheduled, I looked
at it this way. My customer has a menu for administration. This is
separate than maintenance. Administration has two functions.

1. Get orders
2. Cleanup

Get orders will show a list of all order files and they can be viewed,
printed and archived.
Cleanup cleans up all temporary files in the orders file directory that are
3 days or older, based on a value in the config file.
I inform them to run a cleanup at least once when getting orders. My
shopping cart cleans up files when orders are complete and only leaves
successful order files. I cannot determine if someone fails to complete a
shopping experience but I can try to do cleanup with Session_OnEnd. I found
several issues with that approach. So, I chose to just make a generic
routine that cleans up the files. There are 2 files left if the order is
not completed for each shopper. 50 shoppers = 100 files. They are single
digit k byte XML files. 100 files would be less than 1mb. This is only for
unprocessed orders and they are only created if someone leaves something in
their shopping cart and either leaves the site, closes their browser or
times out.

I also didn't want to clean them automatically in case someone was having
trouble and called support. This would give the support person something to
look at so the order could be completed on the phone.

For those who host their own sites, I can offer an automated cleanup, if
desired. Nobody yet has requested this process be automatic since cleanup
takes care of it and only takes seconds at the most.

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
P

Propin

Have the same problem, IWAM_machinename did not solve my problem. Have
created the following test code (file is never deleted on my IIS6 Win2003
environment, any idea?):

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

Sub Application_OnStart

End Sub

Sub Session_OnStart

Set objFileSystemObject = Server.CreateObject("Scripting.FilesystemObject")


objFileSystemObject.CreateTextFile "C:\temp\error\Test.txt", True

Set objFileSystemObject = Nothing


End Sub

Sub Session_OnEnd


Set objFileSystemObject = Server.CreateObject("Scripting.FilesystemObject")


objFileSystemObject.CreateTextFile "C:\temp\error\Test.txt", True

Set objFileSystemObject = Nothing

End Sub

Sub Application_OnEnd

End Sub

</SCRIPT>

/Propin
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top