Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6139979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:03:33+00:00 2026-05-23T18:03:33+00:00

Question #1 I want to know when am I supposed to use: Session.Abandon() //

  • 0

Question #1

I want to know when am I supposed to use:

Session.Abandon() // When I use this during tracing and after calling it- I find the session still has a value.

And when am I supposed to use :

Session.Clear()

When should I use each specific method?


  • In general?
  • In my specific case?

I check if session is not equal null in Page Load. If session is equal to null, I wanna to clear session and redirect to the login page?

Should I use something like this:

private void initSession()
{
    Session.Clear();
    Session.Abandon();
    Response.Redirect("LoginPage.aspx");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:03:34+00:00Added an answer on May 23, 2026 at 6:03 pm

    In ASP.NET, when should I use Session.Clear() rather than Session.Abandon()?

    Session.Abandon() destroys the session
    and the Session_OnEnd event is
    triggered.

    Session.Clear() just removes all
    values (content) from the Object. The
    session with the same key is still
    alive.

    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.

    Use Session.Clear(), if you want that
    the user remaining in the same session
    (if you don’t want him to relogin for
    example) and reset all his session
    specific data.

    What is the difference between Session.Abandon() and Session.Clear()

    Clear – Removes all keys and values
    from the session-state collection.

    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.

    Session.Clear can be compared to
    removing all books from the shelf,
    while Session.Abandon is more like
    throwing away the whole shelf.

    …

    Generally, in most cases you need to
    use Session.Clear. You can use
    Session.Abandon if you are sure the
    user is going to leave your site.

    So back to the differences:

    • Abandon raises Session_End request.
    • Clear removes items immediately, Abandon does not.
    • Abandon releases the SessionState object and its items so it can garbage
      collected.
    • Clear keeps SessionState and resources associated with it.

    Session.Clear() or Session.Abandon() ?

    You use Session.Clear() when you don’t
    want to end the session but rather
    just clear all the keys in the session
    and reinitialize the session.

    Session.Clear() will not cause the
    Session_End eventhandler in your
    Global.asax file to execute.

    But on the other hand
    Session.Abandon() will remove the
    session altogether and will execute
    Session_End eventhandler.

    Session.Clear() is like removing books
    from the bookshelf

    Session.Abandon() is like throwing the
    bookshelf itself.

    Question

    I check on some sessions if not equal null in the page load. if one of them equal null i wanna to clear all the sessions and redirect to the login page?

    Answer

    If you want the user to login again, use Session.Abandon.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from this question , I now want to know how to stop
I've read this question, but I want to know how can I delete the
Sorry if the question has already posted, I want to know if GAE support
There's already a question on this here. But i want to know if its
This is a very newbie question. I want to know how to create a
I know this question isn't directly programming related, but since I want to be
I know this question is probably stoopid. But I just don't want to cause
So I have this certain table. I know I'm not supposed to use table
My question is very fundamental, I want to know straight forward and right way
I don't know if i am asking a silly question but I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.