?
Solved

How can I clear a session variable?

Posted on 2005-05-13
16
Medium Priority
?
190 Views
Last Modified: 2011-09-20
Is there a one liner to clear a session variable?

I need to clear a dataset in session when "not ispostback"...

thx.
0
Comment
Question by:Weller0123
  • 5
  • 5
  • 4
  • +2
16 Comments
 
LVL 13

Assisted Solution

by:softplus
softplus earned 1200 total points
ID: 14000475
Session("mydataset") = Nothing
:)
0
 
LVL 33

Expert Comment

by:raterus
ID: 14001810
that's two lines, btw, the smiley will produce a compilation error :-)
0
 
LVL 13

Expert Comment

by:softplus
ID: 14001826
oops:
 Session("mydataset") = Nothing ' :)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 33

Expert Comment

by:raterus
ID: 14001845
there is nothing to smile about, you are murdering the poor session variable!
0
 
LVL 13

Expert Comment

by:softplus
ID: 14001858
Session("yourdataset") = Nothing ' for you, all for me
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 14002878
Session.Remove("keyName") is arguably more intuitive
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 800 total points
ID: 14002887
plus this.

Session("keyName") = Nothing  
does not remove the item. It just sets the Item as Nothing. The item is still in the Session.

Session.Remove("keyName") removes the Item completely.

Session("Item") = 1
Response.Write(Session.Count & "<br>")
Session("Item") = Nothing
Response.Write(Session.Count & "<br>")
Session.Remove("Item")
Response.Write(Session.Count)


wil give you

1 'set to 1
1 'set to nothing
0 'remove
 
0
 
LVL 13

Expert Comment

by:softplus
ID: 14002895
If he wanted to reuse the same variable with something else, wouldn't it make sense to set it to Nothing instead of removing it? Or does that have no influence? (just wondering)
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 14002900
dunno. but it would be best to not have items in the session set to nothing... after all whether it is there or not
If Session("Item") Is Nothing Then
...
End If

would amount to the same thing.
0
 

Expert Comment

by:khacduyst
ID: 14008856
hi Weller0123,
if u want to remove session variable u just set it value is nothing and then GC collect it and free memory of webserver the syntax below :
Session("variable name") = Nothing  

or remove it using :
Session.Remove("variable name")

good luck   : )
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 14009645
khacduyst,  welcome to EE. Part of the rules in EE is not to repeat the answers given by other experts. You just did that. So please do not do that in the future again.
0
 

Author Comment

by:Weller0123
ID: 14022245
LOL!!!!!!!  @  this thread.

I don't know whether to award points on content or comedic value.
0
 
LVL 13

Expert Comment

by:softplus
ID: 14022273
To be (removed) or to be nothing :)
0
 
LVL 33

Expert Comment

by:raterus
ID: 14022355
That was the question,
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous instantiation,
Or to take arms against a sea of exceptions...
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 14023507
LOL raterus,
mine tongue doth not gainsyeth thee that there ever was such a poetic soul as thee fighting the unseemly sea of exceptions.

[Now see what you have started =P~~]
0
 
LVL 33

Expert Comment

by:raterus
ID: 14023665
Good Night, Good night!

Parting is such sweet sorrow, that I shall say good night till it be morrow!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

612 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