Reputation: 2287
I have my web-application developed with .net core 3. I deploying it on hosting which is running IIS. One of the most important modules of my application is scheduled tasks that should executes during all application lifetime. The issue I faced is that application stopping after 1 or 2 hours of inactivity.
I deploy the application with the 'out-of-process' approach. To reach the goal I initializing application with this code at the Program.cs
:
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseIISIntegration();
webBuilder.UseEnvironment(EnvironmentName);
webBuilder.UseStartup<Startup>();
});
Also, I put these settings to the .scproj
<PropertyGroup>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>
Then I check my headers I can see this entry in my response headers:
Server: Kestrel
My schedules are implemented IHostedService
and should run as background tasks.
All the above gives me the opinion that the application should run non-stop and shouldn't be disposed by IIS because it's running at the Kestrel and use IIS as a proxy server only. But in reality, it is different. Using logs I can see how after an hour or two my application stops running and does not log anymore.
Also, I don't have an access to the IIS because it is out of my permission, so I can't change it's setting. Does anybody have any idea how to get my application to run non-stop?
Upvotes: 2
Views: 3383
Reputation: 2380
You will need to set these IIS settings to prevent your application from automatically being recycled due to inactivity.
App Pool Settings:
Website settings: On the Advanced Settings for the website, change Preload Enabled to true.
Upvotes: 5
Reputation: 5861
Better way is change the iis
settings.
Run this powershell
script to keep alive application in iis
. and if your server has been restarted, by this script your application run automatically
$AppPool
is name of your application in Application Pools
$Site
is name of your application in Sites
## IIS WebAdmin Module
Import-Module WebAdministration
$AppPoolInstance = Get-Item IIS:\AppPools\$AppPool
Write-Output "Set Site PreLoadEnabled to true"
Set-ItemProperty IIS:\Sites\$Site -name applicationDefaults.preloadEnabled -value True
Write-Output "Set Recycling.periodicRestart.time = 0"
$AppPoolInstance.Recycling.periodicRestart.time = [TimeSpan]::Parse("0");
$AppPoolInstance | Set-Item
Write-Output "Set App Pool start up mode to AlwaysRunning"
$AppPoolInstance.startMode = "alwaysrunning"
Write-Output "Disable App Pool Idle Timeout"
$AppPoolInstance.processModel.idleTimeout = [TimeSpan]::FromMinutes(0)
$AppPoolInstance | Set-Item
if ($appPoolStatus -ne "Started") {
Write-Output "Starting App Pool"
Start-WebAppPool $AppPool
} else {
Write-Output "Restarting App Pool"
Restart-WebAppPool $AppPool
}
This link maybe helpful for you
Upvotes: 0