1

I have an ASP.NET Core website hosted on IIS. This site uses a IHostedService added with services.AddHostedService method. I set up IIS App pool to "AlwaysRunning" and "0" to Idle time-out.

The thing I need is to run this service right after the AppPool (and IIS) starts. However, it starts after I access any page of it. I understand, that this case is when app is created or whatever.

Is there any way to start the website automatically and keep it online?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
cyberpug2077
  • 192
  • 2
  • 13
  • 1
    Please remove this as a duplicate. That answer only provides half the information. Setting `Start Mode` to `Always Running` only effects the app pool. The ASP.NET Core application will still not be 'warmed up'. Hence the reason you need to set the hosting model to `InProcess`. – Travis Boatman Jan 18 '19 at 06:53
  • The answer given in a related topic does not works on my issue. Process starts, but with an exception. – cyberpug2077 Jan 18 '19 at 07:06

2 Answers2

2

This is possible with IIS 8 and ASP.NET Core 2.2.

In IIS you'll need to set the Start Mode to Always Running https://blogs.msdn.microsoft.com/vijaysk/2012/10/09/iis-8-whats-new-application-pool-settings/

Then in your .csproj you'll need to add <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2#in-process-hosting-model

If you're interested here is the Github issue for this feature: https://github.com/aspnet/AspNetCore/issues/3849

Travis Boatman
  • 2,252
  • 16
  • 31
0

Register at any ping/check/monitoring free service, and it will make request to your site every 5/10/15 minutes

Dmitry
  • 16,110
  • 4
  • 61
  • 73