Proper way of destroying unused session objects

  • Thread starter Thread starter NETUser2004
  • Start date Start date
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
 
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.
 
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......
 
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?
 
Back
Top