By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

session.remove vs session.contents.remove

P: n/a
Is there a reason to use session.remove over session.contents.remove?

Don't they both remove the key and data from the contents collection?

I assume that session(x) = nothing does essentially the same thing but is
actually deleted later by the GC.

Thanks,

Tom
Aug 4 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"tshad" <ts**********@ftsolutions.comwrote in message
news:e1**************@TK2MSFTNGP06.phx.gbl...
Is there a reason to use session.remove over session.contents.remove?
Session.Remove isn't even listed in MSDN - Session.Contents.Remove is...
http://msdn.microsoft.com/library/de...710538d6c1.asp
Aug 5 '06 #2

P: n/a
re:
Session.Remove isn't even listed in MSDN
Yes, it is :

http://msdn2.microsoft.com/en-us/lib...te.remove.aspx

You use Session.Contents.Remove in ASP and Session.Remove in ASP.NET.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message news:e%****************@TK2MSFTNGP04.phx.gbl...
"tshad" <ts**********@ftsolutions.comwrote in message
news:e1**************@TK2MSFTNGP06.phx.gbl...
>Is there a reason to use session.remove over session.contents.remove?

Session.Remove isn't even listed in MSDN - Session.Contents.Remove is...
http://msdn.microsoft.com/library/de...710538d6c1.asp

Aug 5 '06 #3

P: n/a
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:e0**************@TK2MSFTNGP04.phx.gbl...
re:
>Session.Remove isn't even listed in MSDN

Yes, it is :

http://msdn2.microsoft.com/en-us/lib...te.remove.aspx
That's HttpSessionState.Remove, not Session.Remove...
You use Session.Contents.Remove in ASP and Session.Remove in ASP.NET.
Seems like you can use either in ASP.NET 2...
Aug 6 '06 #4

P: n/a
re:
>http://msdn2.microsoft.com/en-us/lib...te.remove.aspx

That's HttpSessionState.Remove, not Session.Remove...
Read again, Mark :

HttpSessionState.Remove Method
Deletes an item from the session-state collection.

....which is exactly what Session.Remove does.

The long explanation :

Access to session values and functionality is available using the HttpSessionState class,
which is accessible through the Session property of the current HttpContext,
or the Session property of the Page.

Read through this link :
http://msdn2.microsoft.com/en-us/lib...t.session.aspx

When you use Session.whatever, you are really using a shortcut to HttpContext.Session,
which provides access to the HttpSessionState class.

Because ASP.NET pages contain a default reference to the System.Web namespace
(which contains the HttpContext class), you can reference the members of HttpContext
on an .aspx page without the fully qualified class reference to HttpContext.

For example, you can use just Session("SessionVariable1")
to get or set the value of the session state variable SessionVariable1.

But, in reality, Session("SessionVariable1") and
HttpContext.Current.Session("SessionVariable1").
are both one and the same thing : ways to access the HttpSessionState class.

re:
>You use Session.Contents.Remove in ASP and Session.Remove in ASP.NET.
Seems like you can use either in ASP.NET 2...
You can, although I don't see the purpose of writing extra, unneeded code (why use
"Session.Contents.Remove" when "Session.Remove" will do the exact same thing ?)
....but try using Session.Remove in ASP.

You'll get this nasty spitback at you :
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'Remove'

:-)

Bottom line : Session is not an ASP nor an ASP.NET object.

Session is an IIS object to which both ASP and ASP.NET
provide access to, using different methods and properties.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:e0**************@TK2MSFTNGP04.phx.gbl...
>re:
>>Session.Remove isn't even listed in MSDN

Yes, it is :

http://msdn2.microsoft.com/en-us/lib...te.remove.aspx

That's HttpSessionState.Remove, not Session.Remove...
>You use Session.Contents.Remove in ASP and Session.Remove in ASP.NET.
Seems like you can use either in ASP.NET 2...

Aug 6 '06 #5

P: n/a
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
Bottom line : Session is not an ASP nor an ASP.NET object.

Session is an IIS object to which both ASP and ASP.NET
provide access to, using different methods and properties.
Thanks for the explanation.
Aug 6 '06 #6

P: n/a

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:O2**************@TK2MSFTNGP02.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
>Bottom line : Session is not an ASP nor an ASP.NET object.

Session is an IIS object to which both ASP and ASP.NET
provide access to, using different methods and properties.

Thanks for the explanation.
Me too.

It actually answered some explanation on having to use fully qualified names
when using VS and not having to if you build your pages in DW (which I
normally do). So when I would go to the couple of actual dlls that I have
built by hand using DW and then compiling from the command line, I find that
I need to use the FQN which I always need to look up since I normally don't
have to use them and always forget which ones to use.

Thanks,

Tom
Aug 8 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.