Keeping an ASP.Net Core/6/7/8 app alive in IIS

Ste Griffiths - Dec 21 '23 - - Dev Community

There are three things you have to do.

First, install the ‘Application Initialization’ IIS feature on the server! This caught me out.

Next, configure your applicationInitialization settings in web.config or IIS:

  <system.webServer>
    <applicationInitialization doAppInitAfterRestart="true">
      <add initializationPage="/some-route" hostName="hostname.example.com" />
    </applicationInitialization>
  </system.webServer>

Enter fullscreen mode Exit fullscreen mode

The hostname property doesn’t need a scheme (like https://); just the raw hostname.

I believe the initializationPage can be the root route (/) but it might be best to specify a page/file name. The docs say the default value is "" but that doesn’t mean it would work…

Lastly, in the Application Pool settings for the target app pool, in Advanced Settings, set Start Mode to AlwaysRunning and the Idle Time-out to 0.

See the excellent Hangfire docs for Making ASP.NET Core application always running on IIS. The only part not covered there is installing the server role! 😩

Have fun out there ☔

. . . . . . . . . . . . . . . . . . . . . . .