Code to abandon session variables

Which of the codes below is better and what would the difference be ?

<%
 Session.Contents.RemoveAll()
 %>

<script language=vbscript runat=server>
Session.Abandon()
</script>
LVL 1
AleksAsked:
Who is Participating?
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
essentially they do the same thing, except Session.Abandon includes Session.RemoveAll and also deletes the session id created for the session. It will also create a new session ID.

To truly delete the session, use Session.Abandon()
0
 
AleksAuthor Commented:
Thanks !
0
 
AleksAuthor Commented:
:)
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
<%
Session.Contents.RemoveAll()
Session.Abandon()
%>

The Contents.RemoveAll clears the contents stored in the session https://msdn.microsoft.com/en-us/library/ms524866(v=vs.90).aspx while Abandon destroys the objects https://msdn.microsoft.com/en-us/library/ms524310(v=vs.90).aspx  Note that if at the top of the page you use Abandon, you can still access sessions on the rest of the page.

If you are using this for a logout I would do something like

session("user_name") = ""
session("user_auth")=""
Session.Contents.RemoveAll()
Session.Abandon()

Open in new window

0
 
AleksAuthor Commented:
Thanks !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.