skip to Main Content

Session.Clear (); Does this empty all session on asp.net? Can I delete a specific session, such as Session["USER_ID"].Remove()? Or session["USER_ID"].Clear ();

2

Answers


  1. Session.Clear() can be used if you want that the user remaining in the same session (prevent him from doing relogin) and just reset all of his session specific data. The reason for that is because Session.Clear() Removes all the keys and values from the session-state collection. It actually removes all values from the Object. The session with the same key is still alive.

    By the way, the Session.Abandon() removes all the objects stored in a Session.

    So, if you use Session.Abandon(), you lose that specific session and the user will get a new session key. You could use it for example when the user logs out.

    Check out this article for more info – http://csharpexample.com/CsharpExampleSeeDetail.aspx?Did=78&CatID=29

    Login or Signup to reply.
  2. Session.Clear (); Removes all keys and values from the session-state collection.

    Session.Remove(); remove values in session state

    There are many ways to nullify session in ASP.NET. Session in essence
    is a cookie, set

    on client’s browser and in ASP.NET, its name is usually
    ASP.NET_SessionId. So,

    theoretically if you delete that cookie (which in terms of browser
    means that you set

    its expiration date to some date in past, because cookies can’t be
    deleted by

    developers), then you loose the session in server. Another way as you
    said is to use

    Session.Clear() method. But the best way is to set another
    irrelevant object

    (usually null value) in the session in correspondance to a key. For
    example, to

    nullify Session["FirstName"], simply set it to Session["FirstName"] = null.

    see this link
    How to remove specific session in asp.net?

    also this link can help you
    What is the difference between Session.Abandon() and Session.Clear()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search