How to find out why an ASP.NET web application is being restarted

In my web application Application.End is called after every request for some reason and the application is restarted. When I set a breakpoint in Applicaion_End I don’t get a useful stack trace. Furthermore, there are no entries in Event Viewer. According to MSDN, the following could cause an application restart:

  • Adding, modifying, or deleting assemblies from the application’s Bin
    folder.
  • Adding, modifying, or deleting localization resources from the
    App_GlobalResources or App_LocalResources folders.
  • Adding, modifying, or deleting the application’s Global.asax file.
  • Adding, modifying, or deleting source code files in the App_Code
    directory.
  • Adding, modifying, or deleting Profile configuration.
  • Adding, modifying, or deleting Web service references in the
    App_WebReferences directory.
  • Adding, modifying, or deleting the application’s Web.config file.

I guess that my code changes some file which triggers an application restart. Is there any way to find out what exactly causes the application restarts?

Edit: I solved my problem now by stepping through the code and watching the timestamps in Explorer. On application startup I’m reading a value from an access database which causes a .ldb file to be created and deleted. However, this question has not been answered yet. Is there any log that keeps record of such events that cause the application to be restarted?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Tess Ferrandez wrote a good blog post on how to determine the reason for App Domain recycling. Tess has this to say on how to log the restart event:

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:WINDOWSMicrosoft.NETFrameworkv2.0.50727CONFIG 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="" />

To turn on logging for IIS6 you can use:
cscript adsutil.vbs Set w3svc/AppPools/DefaultAppPool/LogEventOnRecycle 255

For IIS7 you can control it from the IIS manager – Application pools – Advanced Settings.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x