Solved

Cleaning up Session Variables

Posted on 2004-08-12
4
215 Views
Last Modified: 2010-04-15
Hi All,

I have a question about session variables ...

I know that they are basically the best way of securely communicating between the diffrent pages of the application, but I know that since they sit on the server, they take up memory.

Is there a way of clearing the memory of sesion variables ?

eg: Session["FIRST"] = "Hello World";
Session["Second"] = 3.141527;

Now if I want to clear them what do I do ...

I have tried setting to "" and 0 .... and also to setting both to null ... but I'm not sure if that is enough ...
0
Comment
Question by:Pete2003
4 Comments
 
LVL 24

Expert Comment

by:Justin_W
ID: 11788464
Use:
   Session.Remove("Second")
or
   Session.Clear()
or
   Session.Abandon()
0
 
LVL 9

Expert Comment

by:glsac
ID: 11789953
Session.Abandon() <--- use this one
0
 

Author Comment

by:Pete2003
ID: 11791144
Wan't the Session.Abandon() clear all my session variables ??

I want to be able to clear specific ones and not the whole thing ...
0
 
LVL 1

Accepted Solution

by:
thefallguy earned 400 total points
ID: 11793168
Session.Abandon() will destroy your session as will Session.Clear(). You can use Session.Contents.Remove(Session["Second"]) to remove the variable from the collection of information about the current session.

Take this example. I have 3 session variables and i want to remove only the ones starting with SW. It is in VB .NET.

Session("SW.1")="Test 1"
Session("SW.2")="Test 2"
Session("Other")="Other"

For Each SessionItem in Session.Contents
  If Left(SessionItem,3) = "SW." then
    Session.Contents.Remove(SessionItem)
  end if
Next
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net How to Exit Sub - Exit Form??? 5 58
System.Security 2 27
SSRS subreport with parameter 3 34
Can I command line build a C# application? 6 33
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question