IIS 回收全局.asax
是否可以在 global.asax 中捕获回收事件?
我知道 Application_End 会被触发,但是有没有办法知道它是由应用程序池的回收触发的?
谢谢,Lieven Cardoen 又名 Johlero
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在 Scott Guthries 的博客上找到了这篇文章:
记录 ASP.NET 应用程序关闭事件
I found this article on Scott Guthries's blog:
Logging ASP.NET Application Shutdown Events
所以,这是一个如何运作的想法。
基于我的之前的回答(附加到AppDomain.CurrentDomain.ProcessExit)和stephbu 的评论:
我建议采用以下策略:
在(常规)ProcessExit 处理程序(我们认为在应用程序池回收时不会调用该处理程序)中,将一些文件写入磁盘,例如“
app_domain_end_ok.tmp
”。然后在 global.asax 的 Application_Start 中检查此文件。 如果它不存在,则表明应用程序未以干净的方式终止(或者这是第一次启动)。 检查后不要忘记从磁盘中删除该文件。
我自己没有尝试过,但值得一试。
So, here is an idea how this could work.
Based on my previous answer (attach to AppDomain.CurrentDomain.ProcessExit) and stephbu's comment:
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.
我自己从未尝试过,但您可以尝试将事件处理程序附加到 AppDomain 的 ProcessExit 事件。
我希望这有帮助!
I've never tried this myself, but you could try to attach an event handler to the ProcessExit event of the AppDomain.
I hope this helps!
我在附加到 DomainUnload 事件方面更加成功,它是在 AppPool 回收和 AppPool 本身停止时触发的。
AppDomain.CurrentDomain.DomainUnload += this.CurrentDomainOnProcessExit;
I was much more successful with attaching to DomainUnload event, it is triggered on AppPool recycle and stoppage of the AppPool itself.
AppDomain.CurrentDomain.DomainUnload += this.CurrentDomainOnProcessExit;