Saturday, March 24, 2012

What is the best way to end session?

Hi all,

I noticed that there are three methods that can remove session
variables
Session.Clear()
Session.RemoveAll()
Session.Abandon()

Now my question as is stated on the subject, what is the best way to
end a session?
I know that the name itself is telling me that Sessin.Abandon() should
be the methond called when ending a session, but if the other two
methods clear or remove all the variables, isn't that the same, since
if I want to go to a page that requires a session variable it just
won't have it?
Actually I found using either RemoveAll or Clear, better than Abandon,
since the Remarks on the Abandon method on MSDN already state that you
can still access session variables after calling the method.
Could anybody explain the difference among these methods?The first 2 only remove session variables you have stored so far. The
session itself is still alive.

Session.Abandon is the only one of those that actually kills the session.

"Hugo Flores" <hugo.flores@.ge.com> wrote in message
news:1121360161.953896.131270@.g47g2000cwa.googlegr oups.com...
> Hi all,
> I noticed that there are three methods that can remove session
> variables
> Session.Clear()
> Session.RemoveAll()
> Session.Abandon()
> Now my question as is stated on the subject, what is the best way to
> end a session?
> I know that the name itself is telling me that Sessin.Abandon() should
> be the methond called when ending a session, but if the other two
> methods clear or remove all the variables, isn't that the same, since
> if I want to go to a page that requires a session variable it just
> won't have it?
> Actually I found using either RemoveAll or Clear, better than Abandon,
> since the Remarks on the Abandon method on MSDN already state that you
> can still access session variables after calling the method.
> Could anybody explain the difference among these methods?
Clear() and RemoveAll() perform the same thing: remove the session variables
but keep the current session in memory. Whereas, Abandon() ends the current
session.

"Hugo Flores" <hugo.flores@.ge.com> wrote in message
news:1121360161.953896.131270@.g47g2000cwa.googlegr oups.com...
Hi all,

I noticed that there are three methods that can remove session
variables
Session.Clear()
Session.RemoveAll()
Session.Abandon()

Now my question as is stated on the subject, what is the best way to
end a session?
I know that the name itself is telling me that Sessin.Abandon() should
be the methond called when ending a session, but if the other two
methods clear or remove all the variables, isn't that the same, since
if I want to go to a page that requires a session variable it just
won't have it?
Actually I found using either RemoveAll or Clear, better than Abandon,
since the Remarks on the Abandon method on MSDN already state that you
can still access session variables after calling the method.
Could anybody explain the difference among these methods?
Hi Marina,

Thanks for the clarification.
Do you know the difference betweeen RemoveAll and Clear?
I guess Siva already answered this.
Thank you all.

0 comments:

Post a Comment