Avatar of Aleks
Aleks
Flag 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>
VB ScriptASPMicrosoft SQL Server

Avatar of undefined
Last Comment
Aleks

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Big Monty

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Aleks

ASKER
Thanks !
Aleks

ASKER
:)
Scott Fell

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

Your help has saved me hundreds of hours of internet surfing.
fblack61
Aleks

ASKER
Thanks !