How to delete some temp files at the end of a session

D

David Hearn

I am using some temporary text files and xml files to store some data in
during a users session. When their session ends (they leave the site or
their session times out) I need to delete these files. What is the best way
to do this?

Thanks in advance!
 
P

Patrice

My personal preference would be just to delete these files as soon as I'm
done with them (if this is for caching you could cache using the .NET cache
for a given period of time) or using a regular housekeeping task (either as
a scheduled task or during the construction of some other temp files) or
when the user logs again.

You can also try the session_end event but it is perhpas no more reliable as
in the old days (for example if the app i s restarted I'm not sure it will
occurs, it d"onest occurs AFAIK if you swithc to the SQL Server session
provider and so on).

Patrice
 
G

Guest

Of course, you'll need to write code for the SESSION_END event in gloal.asax. You'll also need some way of keeping track of the files that were created for given session, in order to delete those without deleting anything that belongs to another session. (Maybe your already doing that, in which case, it wouldn't be an issue.) One option might be to write code into SESSION_START to create a directory in some work area - using the SESSION ID - or some form of unique identifier. Save all files for a given session in that directory, and then blow away the whole shooting match on SESSION_END. Read up on the Directoy Class - I think that pretty much covers what you will need

HTH
 

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,020
Latest member
GenesisGai

Latest Threads

Top