Search code examples
asp.netpage-lifecycledisposing

Can I control cleaning items when user leaves the request?


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.)


Solution

  • 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.