locked
Asp.net application is restarting RRS feed

  • Question

  • User-1721575182 posted

    We are seeing an issue where our asp.net application is restarting every few hours. Based on event logs, we believe it is not caused by IIS restarts or Azure VM reboots. Also, we don't see unhandled exceptions in the event logs.

    We have full access to the machines. How can we find more diagnostic information to root cause the restarts?

    Thursday, April 4, 2019 6:14 PM

All replies

  • User283571144 posted

    Hi tgrunnagle,

    We have full access to the machines. How can we find more diagnostic information to root cause the restarts?

    According to your description, I suggest you could try to follow this answer to know how to use HostingEnvironment.ShutdownReason property in  global.asax find out the application shutdown reason.

    public class ApplicationPoolService : IApplicationPoolService
    {
        public bool IsShuttingDown()
        {
            return System.Web.Hosting.HostingEnvironment.ShutdownReason != ApplicationShutdownReason.None;
        }
    
        public ApplicationShutdownReason GetShutdownReason()
        {
            return System.Web.Hosting.HostingEnvironment.ShutdownReason;
        }
    }
    
    public class HostingEnvironmentRegisteredObject : IRegisteredObject
    {
        public void Stop(bool immediate)
        {
            // second call is done when the Stop is imminent 
            if (immediate)
                return;
    
            var reason = appPoolService.GetShutdownReason().ToString();
            logger.Log(LogLevel.Info, $"HostingEnvironmentRegisteredObject.stop called with shutdown reason {reason}");
        }
    }
    
    // this code should be placed in global.asax.cs
    protected void Application_Start()
    {
        HostingEnvironment.RegisterObject(new HostingEnvironmentRegisteredObject());
    }

    Best Regards,

    Brando

    Friday, April 5, 2019 2:11 AM
  • User-1721575182 posted

    Thank you Brando. We were able to determine the shutdown reason is BinDirChangeOrDirectoryRename using your suggestion.

    Is there any other information we can gather around this shutdown reason? E.g., which file changed.

    Tuesday, April 9, 2019 5:13 PM
  • User475983607 posted

    Thank you Brando. We were able to determine the shutdown reason is BinDirChangeOrDirectoryRename using your suggestion.

    Is there any other information we can gather around this shutdown reason? E.g., which file changed.

    Does your application upload files to the bin directory?  If so, change the process to save file in a different location.

    Tuesday, April 9, 2019 5:36 PM
  • User753101303 posted

    Hi,

    You tried File Explorer and https://www.howtogeek.com/219157/how-to-easily-view-recently-modified-files-in-windows/ to check which files or directories were touched ?

    Or a solution wide search for "bin" with the whole word option maybe should allow to find if you have code that tries to write there ?

    Thursday, April 11, 2019 11:31 AM
  • User-1721575182 posted

    We found the culprit by using the file explorer. Thanks for your help.

    Thursday, April 11, 2019 3:55 PM