Remove an object from Session

F

Frankie

Are these two statements equivalent (i.e., result in the removal of the
object named MyObject from the session)?

Session["MyObject"] = null;

Session.Remove("MyObject");


I would think that the first statement above would result in the object
still being in the Session, but just with a null value. So, if I want it to
be completely gone from the Session I'd have to use the second statement. Am
I correct?
 
J

Juan T. Llibre

re:
So, if I want it to be completely gone from the Session I'd have to use the second
statement. Am I correct?

You are correct.



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
Frankie said:
Are these two statements equivalent (i.e., result in the removal of the object named
MyObject from the session)?

Session["MyObject"] = null;

Session.Remove("MyObject");


I would think that the first statement above would result in the object still being in
the Session, but just with a null value. So, if I want it to be completely gone from the
Session I'd have to use the second statement. Am I correct?
 

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

Top