Deploying Asp.net Core Background Service on IIS

The main purpose of having Background Service within Asp.Net core web api is to make sure that once we start the application pool than Background Service should start immediately.

But in general the design of IIS is such that unless you receive the first request worker process is never started and hence background service won't start automatically.

So basically to achieve that we need to do some config changes on IIS which will help to start the background service automatically.

Below are the steps:

  • Firstly we need to make sure that "Application Initialization" is installed. If not you can add it via "Add Roles and Features Wizard". Once installed make sure you restart you server.


  • Deploy your Asp.Net Core Web Api which has Background Service implemented.
  • Go to "Application Pools" in IIS and select the corresponding application pool.
  • Right Click on it and select "Advanced Settings" and you will see the below screen.

  • Make sure the "Start Mode" is "Always Running".

  • And "Idle Time-out (minutes)" as 0.
  • And lastly most important step is to make sure "Anonymous Authentication" is Enabled.




Without enabling the Anonymous Authentication, your service will never start on it own. Basically from my understanding, once you start the App pool it will try to send the request and for that we need the Anonymous Authentication to be enabled.

And it was bit surprising that no one has mentioned the last step anywhere in the community.

Anyways, I hope it will be helpful. 

Happy Coding.

Comments

Popular posts from this blog

Running Powershell Command Remotely Using C#

Map IIS Worker Process to PID