Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep ASP.NET core app running all the time in IIS

I am hosting an ASP.NET Core (2.2) app in IIS.

The app is using a custom app pool with below settings:

.NET CLR version: No Managed Code
Start Mode: Always Running
Idle Time-out (minutes): 0

My startup code looks like:

WebHost.CreateDefaultBuilder(args)
  .UseStartup<MyStartup>() 
  .Build() 
  .Run();

I am expecting that the app will always run, but after some time the app stops after getting below request:

[Microsoft.AspNetCore.Hosting.Internal.WebHost] Request starting HTTP/1.1 POST http://127.0.0.1:43745/app/iisintegration 0 [Microsoft.AspNetCore.Hosting.Internal.WebHost] Request finished in 5.7107ms 202

The app is a sub app. The parent app is using different app pool, and does have idle time-out.

Is there some setting I am missing to keep the app up all the time ?

like image 983
Brij Avatar asked Aug 16 '19 11:08

Brij


People also ask

Can ASP.NET Core run on IIS?

The module allows ASP.NET Core apps to run behind IIS. If the Hosting Bundle is installed before IIS, the bundle installation must be repaired. Run the Hosting Bundle installer again after installing IIS.


1 Answers

Found a solution which is working. You need to host your ASP.NET Core 2.2 app using in-process hosting model. Below steps can be followed for it.

  1. Install Application Initialization Module (IIS)

Server Manager > Add roles and Features > Server Roles > Web Server (IIS) > Application Development > Application Initialization

  1. IIS > Your App Pool > Start Mode > Always Running

  2. IIS > Your App Pool > Idle Time-out > 0

  3. IIS > Your App > Advanced Settings > Preload Enabled > True

  4. Setup your app for In-Process hosting model (web.config changes for Asp.net core module and code changes to set correct current directory)

More information can be found at:

  • https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2

  • https://github.com/aspnet/AspNetCore.Docs/issues/12232

  • https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2

  • https://github.com/aspnet/AspNetCore/issues/6075

like image 130
Brij Avatar answered Sep 28 '22 18:09

Brij