views:

33

answers:

1

Hi all.

I have a page that allows uploading of multiple files, the files are uploaded constantly, i.e. there are many FileUpload controls and a submit button near each of them and it uploads immediately.

I want, that once the user leaves the page and goes to another page without saving the main container (e.g. the 'item' = a product/note/doc/whatever these files are attached to), the uploaded files should be deleted from server.

In other words: how can I know that the user is not intend to come back (i.e. he shuts down his browser etc.)

+2  A: 

The short answer is that you can't know precisely when the user decides to leave your site, unless she specifically clicks "logout" and is redirected somewhere else.

Your best bet would be to clean up after the user during the Session_End() event handler in Global.asax.

womp
I tried putting a breakpoint in that event handler and it never stops there - ?
Shimmy
I thought about having an alert to the user when he leaves the page but I donno how to tell the server that he said Yes.Besides, if he closed the browser in an uncontrolled way like shutting off the computer or killing the browser process there will be no control upon it.
Shimmy
Session_End() will occur after the session times out, or the user's session is explicitly ended through code by calling Session.Abandon(). The default session timeout is 20 minutes if you haven't changed it in the web.config file. See http://msdn.microsoft.com/en-us/library/h6bb9cz9.aspx for more details about session state.
womp
In other words... if the user leaves your site, shuts down their computer, kills their browser or whatever... 20 minutes later, Session_End() will fire for that user if they don't come back.
womp