Search code examples
iisasp.net-coreentity-framework-migrationskestrel-http-server

Is Kestrel started immediately by IIS AspNetCore module?


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?


Solution

  • 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.