windowsasp.net-coreiis

Auto restart ASP.NET Core application running by IIS after remote server restart not working


To auto restart ASP.NET Core application running by IIS after remote server (Windows 2016 server) restart, I already did these steps but after restarting server, the application still not being restarted automatically by the ApplicationInitialization module, and so every time I need to make a first request to start the asp.net app by myself.

Steps I did

  1. Set the Application Pool to StartMode=AlwaysRunning.
  2. Set the site (from Advanced settings) to preloadEnabled=true.
  3. Install the Application Initialization feature to the Windows installation.
  4. In Configuration Editor, in web.config at system.webServer/applicationInitialization, set doAppInitAfterRestart to True
  5. In Configuration Editor, in web.config at system.webServer/applicationInitialization, add initializationPage "/", hostName ""
  6. In Configuration Editor, in web.config at system.webServer/applicationInitialization, add initializationPage "/about", hostNmae "localhost"

The strange thing is, I did the same steps and the same configuration setting to my local PC IIS server, the auto restarting process works fine and I can see a dummy request from 127.0.0.1 as I used Serilog to log every request.

enter image description here

So the ApplicationInitialization module is working on my local PC.

Anybody know what other things that I may be missing on the remote server?

Or is there any debug methods I can try to see if the ApplicationInitialization module is working properly on the remote server?


Solution

  • The steps I did above was enough to get the ApplicationInitialization module working for Auto restart ASP.NET Core application running by IIS

    To find out why the ASP.NET application was not restarted automatically, I enable Failed Request Tracing for debugging error request, see: Here to enable Failed Request Tracing

    After tracing requests to the IIS server, the ApplicationInitialization module did fire a request to the IIS server once I trigger restart from IIS Manager, but the request failed to send to the ASP.NET application because I set the anonymous authentication=Disabled and windows authentication=Enabled, which prevent the request from ApplicationInitialization module to reach the ASP.NET application, because IIS already response with 401 status. After turning anonymous authentication=Enabled, the auto restart works fine now.