ASP.NET 5 or Core with IIS: Prevent Slow Startup & Cold Boot
When I first started deploying ASP.NET 5 and Core web apps to IIS on Window Server, I found that if the site wasn't accessed for about 20 minutes, there would be an extremely slow load time. These cold boots would take around 10-15x longer than standard page loads.
Cold boots are usually not a problem for sites accessed on a regular basis, however it's a big inconvenience when someone tries to access the app for the first thing in the morning, for example on an intranet or a company's internal backend. There's also times when you might have an infrequently used API which must always have fast load times.
You can apply a fix for the slow start times by editing some values for the site from IIS Manager.
Why IIS Terminates The App
There's a good reason why IIS terminates apps that have not had any recent activity. Some people may have many sites running on a single server and by terminating the process of apps that have not been used for a while, the system is able to free up hardware resources for other apps.
Terminating the app also helps deal with "potential memory leaks" however in the real world this doesn’t really seem to be a problem that most users of C# / ASP.NET Core will experience.
So the termination of apps may not be useful for your use-case, so feel free to alter the timeout by following the below instructions.
Start by opening IIS manager, navigating to Application Pools and then clicking on the application pool used by your website or API. Then click on the Advanced Settings button.
Scroll down until you see Idle Timeout (Minutes) and change this to whatever integer you want. I usually set mine to 1440 minutes which is 24 hours.
And that should be it. IIS should now wait longer before terminating the current process running your app due to inactivity.
As of November 2020, these steps have been tested on the latest version of IIS on Windows Server 2012, 2016 and 2019.
Servers with very low memory may still encounter issues with slow start times if the OS needs to free memory for other processes, however if you're only running one ASP.NET website then this will typically only be an issue on machines with less than 1 or 2GB of RAM.