如何找出重新启动ASP.NET Web应用程序的原因

在我的Web应用程序中,由于某种原因在每个请求之后调用Application.End并重新启动应用程序.当我在Applicaion_End中设置断点时,我没有得到有用的堆栈跟踪.此外,事件查看器中没有条目.根据MSDN,以下可能导致应用程序重新启动:
  • Adding,modifying,or deleting assemblies from the application’s Bin
    folder.
  • Adding,or deleting localization resources from the
    App_GlobalResources or App_LocalResources folders.
  • Adding,or deleting the application’s Global.asax file.
  • Adding,or deleting source code files in the App_Code
    directory.
  • Adding,or deleting Profile configuration.
  • Adding,or deleting Web service references in the
    App_WebReferences directory.
  • Adding,or deleting the application’s Web.config file.

我想我的代码会更改一些触发应用程序重启的文件.有没有办法找出导致应用程序重新启动的确切原因?

编辑:我现在通过逐步执行代码并在资源管理器中查看时间戳来解决我的问题.在应用程序启动时,我正在从访问数据库中读取一个值,该值会导致创建和删除.ldb文件.但是,这个问题还没有得到解答.是否有任何日志记录导致应用程序重新启动的此类事件?

解决方法

Tess Ferrandez写了一篇关于如何确定App Domain回收原因的 blog post. Tess如何记录重启事件:

How do you determine what caused an appdomain restart? In ASP.NET
2.0 you can use the built in Health Monitoring Events to log application restarts along with the reason for the restart. To do
this you change the master web.config file in the
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG directory and add
the following section

<healthMonitoring>
  <rules>
    <add name="Application Lifetime Events Default" 
         eventName="Application Lifetime Events"
         provider="EventLogProvider" profile="Default" minInstances="1"
         maxLimit="Infinite" minInterval="00:01:00" custom="" />

要打开IIS6的日志记录,您可以使用:

cscript adsutil.vbs Set w3svc/AppPools/DefaultAppPool/LogEventOnRecycle 255

对于IIS7,您可以从IIS管理器 – 应用程序池 – 高级设置控制它.

相关文章

引言 本文从Linux小白的视角, 在CentOS 7.x服务器上搭建一个...
引言: 多线程编程/异步编程非常复杂,有很多概念和工具需要...
一. 宏观概念 ASP.NET Core Middleware是在应用程序处理管道...
背景 在.Net和C#中运行异步代码相当简单,因为我们有时候需要...
HTTP基本认证 在HTTP中,HTTP基本认证(Basic Authenticatio...
1.Linq 执行多列排序 OrderBy的意义是按照指定顺序排序,连续...