Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
hi ,

As when program execution starts Application_Start, Session_start these methods from global.asax get called.

Such like this which method is called when program execution stops? and how can i access session variable in this ?


My main problem is i want to clear session variables on browser close. For this i am trying above.

If any else better solution you knows please suggest me.


Thanks in advance.
Posted

The Session property provides programmatic access to the properties and methods of 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. However, class file will not inherit System.web namespace. So we need access like below,
HttpContext.Current.Session("Session_Name")
 
Share this answer
 
Comments
Kiran Sonawane 31-May-11 6:54am    
my 5+
The Application_Start and _End events are related to your web application instance as a whole, i.e. when it is loaded or unloaded from IIS. It is not related to a particular user or session ending. It does not make sense to refer to the 'current session' in these events (think referring to instance properties in a static handler).

Furthermore, it is impossible to detect when the user closes his browser, in the general case.

I think you are trying to solve a problem that doesn't exist: ASP.net cleans up expired (or explicitly terminated) sessions for you already.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900