Internet Information Service (IIS) is a pain for developers and may cause more troubles for them on a shared host where they don’t have full access. One of the usual problems that I encounter is the IIS Application Pool’s Idle Timeout which I can’t update the settings due to insufficient permissions. Let’s see which problem that the Idle Timeout causes and how to deal with it.

1. The Problem of IIS Idle Timeout

If your application implements Session or Cookie Authentication which persists user’s login data and is hosted on a Windows Server by IIS, you may notice the application forced you to logout every 20 minutes even when you set the expiration date to be much more later than that. This is because of the IIS Idle Timeout is set to 20 minutes by default which causes the worker process to shutdown after the set interval time. 

In my application, I used .Net Core Cookie Authentication and keep the data persistent for a year if user login and select Remember Me option.



However, the application keeps asking me to login again after every 20 minutes of being idle. We know it’s the problem of IIS Idle Timeout and will see how to resolve it in 2 case scenarios: when you have and when you don’t have permission to update IIS App Pool’s settings.

2. Resolve IIS Idle Timeout Problem When You Have Permission to IIS Settings

It’s an easy task if you are server administrator and able to update IIS App Pool Settings. You just need to go to Advanced Settings and either extend the Idle Timeout value to be more than 20 or set it to 0 so that there won’t be any Idle Timeout period.

3. Resolve IIS Idle Timeout Problem When You Don’t Have Permission to IIS Settings

It’s me in this case because I purchased a shared ASPHostPortal Windows host server which doesn’t allow me to update IIS Settings. Unfortunately, the App Pool Idle Timeout is set to be 20 by default so my application keeps asking me to login again after 20 minutes.

So, I need to come up with a solution to automatically make a request to the server every 1 minute. By doing so, the worker process will be kept busy and won’t be shutdown by IIS. Let see how I did it in my .Net Core MVC project.

Step 1: Create a Thread Process

The idea is to keep a background running process which can be invoked every 1 minute since the application starts. A thread process can be used to approach this implementation. Create a static class called MyAppContext


In this class, we create a work delegate function which is invoked every 1 minute. This function just does 1 simple job which is uploading an empty string to the server. That’s how to keep the worker process from being shutdown and from being idle. 

Step 2: Call SetupRefreshJob function in StartUp.cs

We need to fire this refresh job once the application starts. That is when we need to look at StartUp class where we can inject dependency for IMemoryCache as well as start the SetupRefreshJob.


You have done great job!

Done! So now your application can keep the IIS App Pool busy every minute and avoid being shutdown. I hope that this post is helpful to you. Please let me know your thoughts in the comment section below. See you next time!

Leave a comment

Your email address will not be published.