IIS回收Global.asax [英] IIS Recycle Global.asax
问题描述
可以在global.asax中捕获一个回收事件吗?
我知道Application_End将被触发,但有一种方法可以知道它是由应用程序池的回收?
thx,Lieven Cardoen aka Johlero
根据我的以前的答案(附加到AppDomain.CurrentDomain.ProcessExit)和 stephbu '的评论:
这将陷入最结构化的流程
拆除 - 但我不知道
它会捕获所有的撕裂。例如
http:// blogs。 msdn.com/jmstall/archive/2006/11/26/process-exit-event.aspx
进程回收将会杀死进程
,如果它似乎被挂起 - 你的处理程序
不会被调用。
我建议以下策略:
在(常规)ProcessExit处理程序(我们假设不会在应用程序池回收中调用),将一些文件写入磁盘,如 app_domain_end_ok.tmp
。 p>
然后在您的global.asax的Application_Start中检查此文件。如果它不存在,这是一个迹象表明应用程序没有以干净的方式终止(或者它是第一次启动)。不要忘了在检查后从磁盘中删除此文件。
我没有尝试自己,但值得一试。
Is it possible to catch an recycle event in the global.asax?
I know Application_End will be triggered but is there a way to know that it was triggered by a recycle of the application pool?
thx, Lieven Cardoen aka Johlero
So, here is an idea how this could work.
Based on my previous answer (attach to AppDomain.CurrentDomain.ProcessExit) and stephbu's comment:
This will trap most structured process teardowns e.g. - but I'm not sure that it will trap all tear downs. e.g. http://blogs.msdn.com/jmstall/archive/2006/11/26/process-exit-event.aspx Process recycle will kill the process if it seems to be hung - your handler wouldn't get called.
I suggest following strategy:
In the (regular) ProcessExit handler (which we suppose will not be called on a application pool recycling), write some file to disk like "app_domain_end_ok.tmp
".
Then in the Application_Start of your global.asax check for this file. If it doesn't exist it is a sign that the application was not terminated in a clean way (or that it is the first time ever it started). Don't forget to delete this file from disk after the check.
I didn't try that myself, but it could be worth a try.
这篇关于IIS回收Global.asax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!