Proper way of destroying unused session objects

N

NETUser2004

Hello,

I am carrying some values into a page using Session object. I would
like to remove the session values that I used on this page [not to
overcrowd session] when the user leaves to another page. But I need
these values as long as user is on this page [If user presses page
refresh, these Session variables must not be erased].

My environment is ASP.NET/VB.NET.


Thanks in advance
-NET User
 
C

Craig Deelsnyder

NETUser2004 said:
Hello,

I am carrying some values into a page using Session object. I would
like to remove the session values that I used on this page [not to
overcrowd session] when the user leaves to another page. But I need
these values as long as user is on this page [If user presses page
refresh, these Session variables must not be erased].

My environment is ASP.NET/VB.NET.


Thanks in advance
-NET User



----------------------------------------------------------

----------------------------------------------------------
color]

A trick I picked up is to have a 'temp bucket', 1 session var which
contains a Hashtable where you can store the values for that page. Then
when the next page loads itself, all it has to do is Clear the Hashtable
entries in that Session var. Pseudo code:

Hashtable ht = new Hashtable()
ht.Add("var1","val1")
ht.Add("var2","val2")
Session["tempbucket"] = New Hashtable()

then on the next page (when this page is no longer being visited), you
can clear the Hashtable (I'd recommend) or write over the 'tempbucket'
variable with a new hashtable.
 
C

Craig Deelsnyder

Sorry, some of my reply's code is C# syntax (which is why I marked it
pseudo code, not in front of VS.NET right now)...you should get the idea
though......
 
J

John Saunders

NETUser2004 said:
Hello,

I am carrying some values into a page using Session object. I would
like to remove the session values that I used on this page [not to
overcrowd session] when the user leaves to another page. But I need
these values as long as user is on this page [If user presses page
refresh, these Session variables must not be erased].

Why bother removing the values? Have you performed a performance analysis
which suggests that removing them will increase your application's
performance?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top