10

Are they the same thing? Or are they different?

I'd read this SO post and this but they are comparing HttpContext.Current.Session and Session not Context.Session. What am I missing/misunderstanding?

Community
  • 1
  • 1
koshikei
  • 103
  • 1
  • 1
  • 5

4 Answers4

17

Context.Session in a page in the same thing as HttpContext.Current.Session. HttpContext.Current.Session is generally used from code that is not directly on a page or that does not have a reference to the current page.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
3

HttpApplication's Session property exhibits different behaviour than does that of the proporty HttpContext.Current.Session. They will both return a reference to the same HttpSessionState instance if one is available. They differ in what they do when there is no instance of HttpSessionState available for the current request.

On this answer you have the complete response:

Difference between Session and HttpContext.Current.Session

Community
  • 1
  • 1
SandroG
  • 121
  • 8
0

Yes, they are exactly the same. Context is the page context, so it's "bigger" (contains more data) than HttpContext.Current, but the property Session of both has the same value.

Andre Soares
  • 1,968
  • 3
  • 21
  • 24
0

Both are same having no difference , some times Current session needs to be accessed by the code which does not inherit from Page (although a bad practice) in those cases the httpcontext.current.session comes very handy and session can be accessed .

Look into this also: Difference between Session and HttpContext.Current.Session

Community
  • 1
  • 1
Paritosh
  • 2,303
  • 2
  • 18
  • 24