Link to home
Create AccountLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

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>
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Aleks

ASKER

Thanks !
Avatar of Aleks

ASKER

:)
<%
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

Avatar of Aleks

ASKER

Thanks !