2

Up until .NET 4.8 you were able to get the shutdown reason via HostingEnvironment.ShutdownReason

The question has been answered before here for .NET Framework 4.8.

In ASP.NET Core this property is no longer available. This question has been asked before for ASP.NET Core here but didn't get answered.

It's possible to register to IHostApplicationLifetime to be notified when ASP.NET is shutting down but this does not provide you the shutdown reason.

The answer to a similar question in 2017 only concerned Kestrel hosting: There is no shutdown reason in ASP.NET Core because most of the original reasons don't apply.

Is there any way to know why IIS shut down the web app when in-process hosting is used?

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
moccajoghurt
  • 159
  • 9
  • 1
    Because almost none of those reasons applies to ASP.NET Core. That's why there's no such property. What are you trying to do? – Panagiotis Kanavos Nov 01 '21 at 11:51
  • 1
    For example, changing the configuration doesn't require a restart. There's no single config file to begin with. An ASP.NET Core application can either read the original or current values explicitly – Panagiotis Kanavos Nov 01 '21 at 11:54
  • 1
    Besides, ASP.NET Core web apps often run as *standalone* applications. Often inside containers, even on Linux. The `ShutdownReason` enum contains only IIS-specific reasons that make no sense in any other hosting scenarios. – Panagiotis Kanavos Nov 01 '21 at 11:56
  • I am dealing with an external shutdown reason. My virtual server provider frequently shuts down the server and I was hoping there is a way to find the reason programmatically. Thanks for the insights, it does make sense that this variable is no longer available. – moccajoghurt Nov 01 '21 at 11:59
  • 1
    Are you using IIS or Kestrel? When that answer was written in-process IIS hosting wasn't yet available – Panagiotis Kanavos Nov 01 '21 at 12:23
  • @PanagiotisKanavos I am using IIS – moccajoghurt Nov 01 '21 at 12:26

0 Answers0