views:

55

answers:

3

Is

System.Web.HttpContext.Current.Session

the same as

System.Web.UI.Page.Session

?

Many thanks in advance.

+5  A: 

Yup; they refer to the same instance.

Andrew Barber
+2  A: 

There is no difference between the two.

Vinay B R
+6  A: 

They do indeed refer to the same instance, but if you look at the methods in Reflector, you can see that they behave a bit differently (in ways that are not likely to matter in most applications):

  • The call to Page.Session uses a cached HttpSessionState reference.
  • The Page method will throw if session state is not enabled, while HttpSessionState.Session just returns whatever is in the "AspSession" bucket of its Items collection.
Jeff Sternal
That is an excellent distinction, Jeff.
Andrew Barber