1

We are facing an issue that locally, when IIS Express is used, methods of Startup class are called immediately after application is started even without launching browser. (It's a Db migration)

However, when application is deployed to IIS Startup class runs only after first request to the site.

Is it IIS/AspNetCore module to blame? And if yes, is it possible to force the start of Kestrel besides making a query after deploy?

9
  • Are you running it in-process or out-of-process?
    – DavidG
    Feb 27, 2019 at 13:28
  • I suppose it is in-proc by default? App pool for unmanaged code. Feb 27, 2019 at 13:40
  • No, it's out of process by default.
    – DavidG
    Feb 27, 2019 at 13:43
  • Then it is out of process. =) Feb 27, 2019 at 13:44
  • 1
    The difference between in proc and out of proc is whether or not IIS acts as a reverse proxy for Kestrel. With out of proc (the previous default), Kestrel runs the app and IIS proxies requests. With in proc (the new default), IIS hosts the app directly and Kestrel is no longer involved. In either case, you still have an app pool in IIS running. By default the app pool will be set to "On Demand" meaning that it will shut itself down after a period of inactivity and then spin up again when there's a request to satisfy. You want to change this to "Always Running". Feb 27, 2019 at 14:14

1 Answer 1

0

Ok, the magic consists of multiple parts:

First, we should havee a running application pool. This is configured by setting Start Mode of the pool to AlwaysRunning (Default is OnDemand). See this question as well.

Second, we must set site's setting Preload Enabled to true. (Site -> Advanced settings).

Third, we specify applicationInitialization section in web.config file.

This article tells, how to perform these actions with PowerShell.


Note: I require application to warm up because I run DB migration at application start up. As we deploy to multiple instances we use rolling deployment to avoid concurrent migrations.

The process is roughly the following:

  • stop all instances
  • deploy new version to each instance sequentially with awaiting period

It introduces short services downtimes, though it's fine for us right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.