Session_End() alternatives for SQL Server session state

偶尔善良 提交于 2019-12-24 03:44:24

问题


I have an application in MVC4 which has some logic in the Session_End() method in Global.aspx.cs.

However, I need to change the session state from InProc to SQLServer, and this means the Session_End() method will not get called.

I've tried to effect a workaround but I couldn't get it to work.

What are the alternatives, if any, to Session_End()? All I need is the ability to run some logic when the session times out.


回答1:


The session doesn't time out when SessionState is in SQLServer mode.

From the MSDN page on Session-State Modes:

SQLServer mode stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.




回答2:


This is just a guess, but if the Session has ended, the Session property will be null or empty?

Perhaps you could test for that, maybe in a BaseController or something which is called for each request.



来源:https://stackoverflow.com/questions/25543983/session-end-alternatives-for-sql-server-session-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!