简体   繁体   English

ASP.NET会话可以比Application更长寿

[英]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. 这可能是一个愚蠢/蹩脚的问题,特别是在使用ASP.NET :)这么长时间之后,但我需要确定。

Is it possible to have session (that is ASP.NET session) outlive the Application (app instance/app domain/Application variable)? 会话(即ASP.NET会话)是否可能比应用程序(应用程序实例/应用程序域/应用程序变量)更长?

In other words, if Application_End is called in the Global.asax, does it indicate that there will be no more active session? 换句话说,如果在Global.asax中调用Application_End,它是否表示不再有活动会话? and any new request will result in a Application_Start followed by an new Session_Start? 任何新请求都会导致Application_Start后跟一个新的Session_Start?

Note, the Session may not always be InProc, the session could be in a State server or SQL server. 注意,会话可能不总是InProc,会话可能在状态服务器或SQL服务器中。

With the default InProc session state, the application will terminate when the last session has expired, at which point Application_End occurs. 使用默认的InProc会话状态,应用程序将在最后一个会话到期时终止,此时将发生Application_End In this scenario the entire appDomain is torn down and all memory freed. 在这种情况下,整个appDomain被拆除并释放所有内存。 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. 如果使用Sql ServerState Server将会话存储在单独的计算机上,那么当应用程序被拆除时,会话可以继续存在。 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. 然后,因为客户端在浏览器中保留原始会话cookie,所以下次访问该站点时会重新启动会话,并且sessionid用于标识其现有会话。

是的,当您在SQL Server中放置状态时,应用程序可能会重新启动,但您仍将保持会话状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM