Without access to the event logs (because you're in a shared hosting environment) the most information you're going to get is from the Application_End
event and by asking the HttpRuntime
(via reflection) for the values of one or two private members that are sadly not exposed publicly.
To do this add the following code to your Application_End
event:
BindingFlags staticFlags =
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField;
BindingFlags instanceFlags =
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField;
HttpRuntime runtime = (HttpRuntime)typeof(System.Web.HttpRuntime)
.InvokeMember("_theRuntime", staticFlags, null, null, null);
if(runtime != null)
{
string shutDownMessage = (string)runtime.GetType()
.InvokeMember("_shutDownMessage", instanceFlags, null, runtime, null);
string shutDownStack = (string)runtime.GetType()
.InvokeMember("_shutDownStack", instanceFlags, null, runtime, null);
// Log shutDownMessage & shutDownStack somewhere
}
If I shutdown or recycle my app's application pool I see the following:
HostingEnvironment initiated shutdown
HostingEnvironment caused shutdown -
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()
at System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand()
at System.Web.Hosting.PipelineRuntime.StopProcessing()
That's probably about as good as it gets.
Update:
I couldn't remember where I found this code but Drew helpfully reminded me it was from a Scott Guthrie blog post.
There are some other private members that could be useful such as:
private ApplicationShutdownReason _shutdownReason;
You can examine these fields in .NET Reflector (if you still have a copy that isn't time-bombed) or one of the alternatives (Open Source Alternatives to Reflector?).
It turns out that this is because ASP.Net was not completely installed with IIS even though I checked that box in the "Add Feature" dialog. To fix this, I simply ran the following command at the command prompt
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
If I had been on a 32 bit system, it would have looked like the following:
%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i
Remeber to run the command prompt as administrator (CTRL+SHIFT+ENTER)
Best Answer
You could easily find the latest recycle time by using this powershell snippet:
Therefore find the process id of your web application in task manager.
First add the following columns via Tools > Select columns... : select PID and Command Line.
Look for any w3wp.exe process and find your application by examining the command-line (application pool name is part of it) and note down its PID.
Then run the powershell script to find the latest recycle time:
Hope this helps