0

Hi I have a situation where I need to mantain the state of a group of documents without storing them in the database.

I was thinking of storing the documents on the filesystem and inside the session the fileName and a GUID , and when the session expires to be able to delete the documents.

The problem is that I do not know exactly how to determine if session expired.

I know if I have something like this: var session = Session["item"] it will return null if no items are inside the sessions.

But how can I handle if the user for example closes the browser.No call has been made to the server when doing that.

In this case I should delete the documents on the filesystem.

Is there anyway to achieve this?

4

3 回答 3

1

Use the Session_End event inside your Global.asax

More information here: http://msdn.microsoft.com/en-us/library/ms178583.aspx

If your session state is OutProc, you may also want to read this: http://blogs.msdn.com/b/amb/archive/2011/06/03/session-onend-or-session-end-won-t-fire-if-you-store-asp-net-sessions-out-of-proc.aspx

于 2013-10-08T05:53:04.853 回答
1

Possible solution will be using the jquery to capture the unload event like this , at the same time put the code in Session_End of global.asax .

               $( window ).unload(function() {
                    //Write your logic to fire ajax call to delete the file                        
                 });

Another workaround that comes to me , have a JavaScript time which will ping to the server saying that , user is still in Session. In Any point of time you do not get the ping for some time go ahead and delete the file. It is really not good solution , but you may use the web socket or long polling logic to track the user Session.

于 2013-10-08T06:08:29.627 回答
1

may these links help you to find your answer -

http://forums.asp.net/t/1153888.aspx

http://www.codeproject.com/Articles/10771/Detect-browser-closing-through-clicks-on-the-X-but

于 2013-10-08T06:14:46.963 回答