-4

I would like to ask you on how to end a session in asp.net when the user clicks log-out because one of my professors found out that when he clicks log-out and click the back button on the browser, the session is still active and he wants that the specific session to be ended, and it that is really what to happen when you click log-out.

Thank you.

Edge
  • 31
  • 2
  • 11

1 Answers1

4

The Abandon method should work (MSDN):

Session.Abandon();

If you want to remove a specific item from the session use (MSDN):

Session.Remove("YourItem");

EDIT: If you just want to clear a value you can do:

 Session["YourItem"] = null;

If you want to clear all keys do:

 Session.Clear();

If none of these are working for you then something fishy is going on. I would check to see where you are assigning the value and verify that it is not getting reassigned after you clear the value.

Simple check do:

 Session["YourKey"] = "Test";  // creates the key
Session.Remove("YourKey");    // removes the key
bool gone = (Session["YourKey"] == null);   // tests that the remove worked

This is from Kelsey's AnswerClick Here

Community
  • 1
  • 1
Aizen
  • 1,807
  • 2
  • 14
  • 28