Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can ASP.NET session live longer than Application

This could be a silly/lame question, especially after working so long with ASP.NET :), but I need to be sure.

Is it possible to have session (that is ASP.NET session) outlive the Application (app instance/app domain/Application variable)?

In other words, if Application_End is called in the Global.asax, does it indicate that there will be no more active session? and any new request will result in a Application_Start followed by an new Session_Start?

Note, the Session may not always be InProc, the session could be in a State server or SQL server.

like image 317
Shreedhar Kotekar Avatar asked Sep 07 '11 22:09

Shreedhar Kotekar


2 Answers

With the default InProc session state, the application will terminate when the last session has expired, at which point Application_End occurs. In this scenario the entire appDomain is torn down and all memory freed. As sessions are persisted in memory they are permanently destroyed at this point, and therefore can never live beyond the life of the application.

If using Sql Server or State Server where the session is stored on a separate machine, then when the application is torn down the sessions can continue to live. Then because the client retains the original session cookie in the browser, the next time they visit the site the session is restarted, and sessionid used to identify their existing session.

like image 51
TheCodeKing Avatar answered Oct 19 '22 09:10

TheCodeKing


Yes, when you put the state in SQL Server the application could restart but you will still maintain the session state

like image 31
MoXplod Avatar answered Oct 19 '22 08:10

MoXplod