what is diffenrece between HttpContext.Current.Seesion and Session?
and if HttpContext is recreated during every new request and destroyed after response then how values stored in the session of HttpContext remains intact during the whole session of a
user (Means a single a session may involve many request then how values in the Session is intact and accessible during different request of a single session)...
thanks in advance.............
Bikesh SrivastavaPosted Jan 12, 2017, 9:03 AM
They're effectively the same, in that they will access the same Session data.
The reason you can call
Sessionin your code-behind is because ASP.Net pages by default extend theSystem.Web.UI.Pagetype. This has aSessionpublic property. If you look at the code for this in Reflector you can see that it just callsHttpContext.Current.Sessionitself (through its ownContextproperty).In other classes you will not have access to that property, but you can use
HttpContext.Current.Sessionto access the session data instead, as long as you're running in the context of a web applicationMidhun TpPosted Jan 12, 2017, 4:27 AM
Mangesh GPosted Jan 12, 2017, 4:26 AM
HttpApplication'sSessionproperty exhibits different behaviour than does that of the propertyHttpContext.Current.Session. They will both return a reference to the sameHttpSessionStateinstance if one is available. They differ in what they do when there is no instance of HttpSessionState available for the current request.Not all
HttpHandlers provide session state. To do so, theHttpHandlermust implement [one or both?] the marker interfacesIRequiresSessionStateorIReadOnlySessionState.HttpContext.Current.Sessionsimply returnsnullif there is no session available.The
HttpApplication's implementation of the Session property throws anHttpExceptionwith the messageSession state is not available in this context.rather than return anullreference.Some examples of HttpHandlers that do not implement session are the the default handlers for normally static resources, such as image and CSS files. Any reference to the
HttpApplication'sSessionproperty in such cases (as inglobal.asaxevent handlers) will result an HttpException being thrown.