views:

297

answers:

3

Hi,

Is there a way to do a Session.Abandon() when the user just kills the session by X'ing out with the little red X box in the upper right corner? I am seeing situations where after an "X out", the user comes back in and it seems like session variables are still present? I guess explorer keeps them intact? (I am unsure of this).

Thanks, James

+1  A: 

The server is typically not aware of such events on the client. The only way the server can be notified about anything is if there is a request sent back to it. I guess you could create such a notification in a JavaScript, but then you should also keep in mind that the session in mind that the session is not per-page but (usually) per user, which means that you would need to keep track of how many tabs/windows the user has opened so that you don't kill the session when you should not.

Personally, I usually try to design the web apps so that they live well with the default handling of sessions, either providing a specific "Logout" command that will kill the session, or simply let it hit the timeout and die.

Fredrik Mörk
If I could capture it with jscript or jquery, I could use a hidden button click to notify the server. Not sure how I would capture it with jscript though.
James
I am no javascript guru, but I would look into the `window.unload` event. Might be better ways though.
Fredrik Mörk
+2  A: 

You can try doing an AJAX type callback in the OnUnload event - however, as someone else mentioned you'd have to be aware of other tabs being open (not easy), and it still won't guarantee you get that event.

There's a combination of things to do to get a similar type of effect.

  • Session Cookie should have a null/empty expiry time. This ensures the browser deletes the session from it's end after the browser is closed.

  • The ASP Session can be set with a short SessionState timeout value. This means if there's no client activity within that period, the Session will expire.

The side effect of this is that if a user is just looking at the site, and not performing activity (regardless of whether the browser is still open) - the session can expire.

This can be worked-around by having a Javascript timer periodically ping back to the server with an AJAX call or similar. The side effect of THIS is that it generates more site traffic.

Will Hughes
A: 

Hi!

I think i know your trouble. i actually can't understand what u r asking me! :-(

But what i inderstood i'll answer that so first of all you can create an event for exiting here is some code

Private Sub frmInventory_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    e.Cancel = True 'Cancels the event so that user cant get out
End Sub

Then u can use My.Settings To save Variables forever! If you dont know where are the settings folow this Project>Whatever Your Applications Name>Settings

That's it!

TheMasterThingMaker