IIS 回收 Global.asax [英] IIS Recycle Global.asax

查看:30
本文介绍了IIS 回收 Global.asax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 global.asax 中捕获回收事件?

Is it possible to catch an recycle event in the global.asax?

我知道 Application_End 会被触发,但有没有办法知道它是由应用程序池的回收触发的?

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?

谢谢,Lieven Cardoen 又名 Johlero

thx, Lieven Cardoen aka Johlero

推荐答案

所以,这是一个如何工作的想法.

So, here is an idea how this could work.

基于我的之前的答案(附加到 AppDomain.CurrentDomain.ProcessExit)和 stephbu 的评论:

Based on my previous answer (attach to AppDomain.CurrentDomain.ProcessExit) and stephbu's comment:

这将捕获大多数结构化流程拆解例如- 但我不确定它会捕获所有的拆解.例如http://blogs.msdn.com/jmstall/archive/2006/11/26/process-exit-event.aspx进程回收会杀死进程如果它似乎挂了 - 你的处理程序不会被调用.

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.

我建议以下策略:

在(常规)ProcessExit 处理程序(我们假设不会在应用程序池回收时调用)中,将一些文件写入磁盘,如app_domain_end_ok.tmp".

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".

然后在 global.asax 的 Application_Start 中检查此文件.如果它不存在,则表明应用程序没有以干净的方式终止(或者它是第一次启动).检查后不要忘记从磁盘中删除此文件.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆