3

I have a asp.net webapplicatoin using session variables. I clear the session values when session_end is fired but the when the application is opened in a new window after closing the previous window, the session values retain.

is there a way that we can get rid of session values.

Thanks in advance ... Phani

Neil Knight
  • 47,437
  • 25
  • 129
  • 188
Buzz Phani
  • 49
  • 2
  • 7
  • 1
    I'd recommend clearing out the session values as soon as you're done with them, rather than waiting for session_end (which may or may not fire). – Brian Driscoll Sep 02 '11 at 13:09
  • The session_start is 'guaranteed' to fire, but unfortunately the session_end is not, so don't rely on that. Can you use a logout event? – Michel Sep 02 '11 at 13:28
  • Thanks for your responses, Brian and Michel. Unfortunately I dont have an option to logout and I cannot clear session values as they being used all over the application. Any other suggestions are welcome... – Buzz Phani Sep 06 '11 at 05:27

2 Answers2

0

New windows/tabs don't create new sessions, new browser instances do.

Also, when the session ends, the session variables are gone. You just can't control when the GC deletes them from memory, however they are no longer accessible.

rick schott
  • 21,012
  • 5
  • 52
  • 81
0

A session does not end when simply closing a window. The session ends when it expires. ASP.NET has no way of knowing if a user closes the window. See MSDN on SessionStateModule.End Event

See this answer for a more thorough explanation.

Of the top of my head, what you could do is detect when the user closes the window e.g. using the unload() event in jQuery, and send a request to a webservice that then ends the session.

Community
  • 1
  • 1
Tchami
  • 4,647
  • 1
  • 32
  • 45