DEV Community

Ste Griffiths
Ste Griffiths

Posted on • Originally published at stegriff.co.uk on

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

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 ☔

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay