Assigning Session to nothing or Session.Abandon
I have seen so many developers once they wanted to destroy session, they used
Session(”A”) = Nothing
Its not a good practice to assign nothing object.
Correct Way:
Session.Abandon
The Session.Abandon method basically destroys a user session.
One thing I would add the current Session object will not delete untill the script on the current page have been processed completely.
Best Way:
FormsAuthentication.SignOut()
Session.Abandon()
Use Forms Authentication.Signout which will removes the forms-authentication ticket from the browser.





Very useful tip. I will definitely use it.
Wounderfull all most all the developers do so. Before readind this artical i also use same like
Session(”A”) = Nothing
Also FormsAuthentication.SignOut() is new thing for me.
Thanks
Just some more notes. Use these three methods according to what you want to do! Think about it.
1) Session.Remove(”A”) is more correct than Session(”A”) = null|Nothing, and it’s absolutely appropriate when you want to just clean up what you’ve put in there.
2) Session.Abandon() removes ALL session values.
3) FormsAuthentication.SignOut() removes the authentication ticket and redirects to the login page.
don’t u think Session.Abandon() will destroy all session keys value whereas through Session(”A”) = Nothing we r just getting rid of Session(”A”) SOMEHOW
just trying to share my thought, pls correct me if i m wrong.
take care, Thanks,
Hi webmaster!
You are right Muhammad Adnan
I think Joggee didnt explain it very well, but it is undestandable
I think:
Session(”A”) = nothing ‘Will set the variable to nothing, but the variable will still be in the session
Session.Remove(”A”) ‘ Will remove the variable from the session
Session.Abandon ‘ Will remove all variables from session, and i just wondering if a new session would be regenerated, bt not, i just tryed that, this only removes session variables but does not generate a new sessionid