locked
remove session RRS feed

  • Question

  • User-1980099983 posted

    I have set up a session Like Session["id"]= some value; now on the same page i want to finish this session. what is the best way abondon, kill, remove etc thanks
    Pls give me the syntax too. thanka

    Monday, August 22, 2011 9:39 AM

Answers

  • User960609757 posted

    Hi,

    you can try

    Session["key"] = null;

    or

    Session.Remove("key");

    Session.Clear stays in the same session.
    Session.Clear will just clear the session data , the session is still alive


    Session.Abandon dumps the current session and starts a new session.
    Session_End will be fired and next request will fire Session_Start


    Session ID will remain same in both cases, as long as the browser is not closed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 24, 2011 3:23 AM
  • User-578657687 posted

    Hi,

    Session.Abandon:

    Once the Abandon method is called, the current session is no longer valid and a new session can be started, and the Session_OnEnd event is triggered.

    Session.Clear:

    Removes all keys and values from the session-state collection. The Session with the same key is still alive.

    Session.Remove:

    Deletes an item from the session-state collection.

    More information please check this link:

    http://forums.asp.net/p/1696421/4495893.aspx/1?Re+Want+to+access+session+variable+in+global+asax+session_end

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 25, 2011 2:35 AM

All replies

  • User1644485212 posted

    You can use

    Session.remove("variable_name");

     

    OR

     

    Session["Variable_name"] = null;

     

    Session.abandon will remove all the session...

     

    Monday, August 22, 2011 9:56 AM
  • User-1062158585 posted

     Session["id"] = "testc";
                Session.Remove("id");

                Session.Clear();

    Monday, August 22, 2011 12:18 PM
  • User-481631678 posted

    You have three options to remove/kill information from Session

    1) Session.Remove("test"), it will delete only one variable

    2) Session.Clear(), it will delete all the variables in session.

    3) Session.Abandon, it will delete all the variables in session and also give new session ID to you.

    Wednesday, August 24, 2011 1:41 AM
  • User1927273029 posted

    Hello,

    Use the two lines to remove the session

    Session.Abandon()

    Session.Clear()

    Wednesday, August 24, 2011 2:05 AM
  • User960609757 posted

    Hi,

    you can try

    Session["key"] = null;

    or

    Session.Remove("key");

    Session.Clear stays in the same session.
    Session.Clear will just clear the session data , the session is still alive


    Session.Abandon dumps the current session and starts a new session.
    Session_End will be fired and next request will fire Session_Start


    Session ID will remain same in both cases, as long as the browser is not closed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 24, 2011 3:23 AM
  • User705563967 posted

    If you want to declear and remove session on same page why you not try to use ViewState you dont need to remove Viewstate its automatically finished when you redirect to another page.

    Wednesday, August 24, 2011 3:31 AM
  • User-578657687 posted

    Hi,

    Session.Abandon:

    Once the Abandon method is called, the current session is no longer valid and a new session can be started, and the Session_OnEnd event is triggered.

    Session.Clear:

    Removes all keys and values from the session-state collection. The Session with the same key is still alive.

    Session.Remove:

    Deletes an item from the session-state collection.

    More information please check this link:

    http://forums.asp.net/p/1696421/4495893.aspx/1?Re+Want+to+access+session+variable+in+global+asax+session_end

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 25, 2011 2:35 AM