locked
SQL SessionState and Session.Abandon() RRS feed

  • Question

  • User-1831556988 posted

    Hi

    We have an application, which uses SessionState in a MS SQL database. I have noticed a behavior, which causes me to ask the following question:

    Let’s say you call Session.Abandon – and when somewhere in e.g. the view/partial view – read information from the session before the of the ASP.NET request. Is the Session when really abandoned at the end of the request – or has the read of the information cancelled the abandon?

    Friday, March 17, 2017 8:56 AM

All replies

  • User-1509636757 posted

    Abandon - removes all the objects stored in a Session. If you do not call the Abandon method explicitly, the server removes these objects and destroys the session when the session times out. It also raises events like Session_End.

    So, when code executed Session.Abondon(), any subsequent request to server that attempts to read Session will not get its value. Abandon never cancelled once it is executed/called in your code.

    Friday, March 17, 2017 9:08 AM
  • User-1831556988 posted

    The reason I ask  is - that sometimes the session does not get abandoned eventhough Session.Abandon() has been called. 

    Friday, March 17, 2017 9:36 AM
  • User-1509636757 posted

    Does it available in subsequent requests as well even after Session.Abondon() ?

    Reference link: Why Does Session Abandon Not Work?

    Session.Abandon() should be used to completely dispose a session including the Session.SessionID.

    But there is a cavert;

    Quote from the MSDN Library - Session.Abandon()

    "When the Abandon method is called, the current Session object is queued for deletion but is not actually deleted until all of the script commands on the current page have been processed. This means that you can access variables stored in the Session object on the same page as the call to the Abandon method but not in any subsequent Web pages."

    Friday, March 17, 2017 9:47 AM