开发者

How to Identify that IIS Restarted?

开发者 https://www.devze.com 2022-12-11 15:55 出处:网络
In my application I save some data related to the users sessions in the database. When the user logoff I cleanup all his session data from the database. So far, so good.

In my application I save some data related to the users sessions in the database. When the user logoff I cleanup all his session data from the database. So far, so good.

But, when IIS is restarted, all the active sessions are invalidated without the chance to gracefully cleanup.

So, I need to iden开发者_StackOverflow中文版tify when IIS is restarted to solve this situation.


I would just put something int the application_start event in the global.asax

http://www.codetoad.com/asp.net_globalasax.asp

Your app has restarted for some reason, and according to your description it'll have to clean all the sessions out of the db regardless if it is from IIS restarting, or the app pool getting recycled etc.

You can't trust your application to set a flag that IIS has signaled a restart in your application_end event, because there are times when it won't fire. For example what happens if the server crashes, or if IIS gets killed outside of it's control (taskkill).


There is a DBNAME_Job_DeleteExpiredSessions job defined on SQL server where your session data is stored. If your SQL Agent service is running, the job will clear old sessions. More info


What about session timeout? do you need to cleanup after timeouts? also keep in mind that you cannot really relay on the Session.End event - it only works for in-process sessions

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号