16

I'm trying to get my ASP.NET application to automatically start whenever the application pool is running.

As per the lots and lots of references online I have already done the following:

  • Set the Application Pool to StartMode=AlwaysRunning
  • Set the site in question (that belongs to beforementioned Pool) to preloadEnabled=true
  • Install the Application Initialization feature to the Windows installation
  • Add the <applicationInitialization> node to the web.config's <system.webServer> node

The web application is based on Owin and has a simple log4net logging statement in it's Startup.Configuration() method. Now when restarting IIS I see that the w3svc.exe process is running, so I know the StartMode=AlwaysRunning is working. There are however no logging messages in the log file.

Navigating to any url (even a nonexisting one) in the application will start the app and add the log line.

Because of the actual work that's done in the startup of the application I really want the application to truly preload, but I seem to be unable to get it done.

Searching this site I have unfortunately not been able to find a solution.

Thanks in advance.

Robba
  • 7,684
  • 12
  • 48
  • 76
  • Did you install the Web Server | Application Development | Application Initialization server feature? See http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization#TOC301259895 – Philippe Monnet Jan 06 '16 at 20:04
  • I did actually, and while I'm unsure what changed, it is working now. I think I just missed a required reboot or something. – Robba Jan 07 '16 at 08:11

1 Answers1

34

To answer my own question for future generations, it seems I was on the right track. To get the application to start in IIS10 (and I assume in IIS 8 as well) you only need the following three steps:

  1. Set the Application Pool to StartMode=AlwaysRunning to make sure the w3svc.exe process is always running for the App Pool.
  2. Set the site in question (that belongs to beforementioned Pool) to preloadEnabled=true
  3. Install the Application Initialization feature to the Windows installation as per the instructions here.

One important thing to note is that if the Application Initialization task was not previously installed on the machine you must reboot the machine. This is what I missed the last time which led to quite some time wasted looking for other things :(

Anyway, setting up those three things will cause the app to actually go through it's initialization, which is especially useful if you want to setup some scheduling task (ea using the Quartz NuGet package).

Note by the way that if you setup auto initialization like above, the application will also automatically start after the shutdown timeout has expired and on application pool recycles.

Seymour
  • 7,043
  • 12
  • 44
  • 51
Robba
  • 7,684
  • 12
  • 48
  • 76
  • 2
    You made my day. Although I didn't had to reboot the machine, iisreset was enough for me to get it working. – Arnold Pistorius Jun 14 '17 at 08:05
  • 1
    I would also add `Idle Time-out (minutes)` equals to 0. It's a setting of Application Pool. – hastrb Jan 30 '20 at 09:51
  • Is it indeed optional to do the `` step described in the [docs](https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-application-initialization#modifications-in-the-applications-webconfig)? – GSerg Oct 29 '21 at 07:54
  • Not sure if you would still remember, but I set my application (.Net Core) to all the steps mentioned. It does restart, but Log4net, and Quartz doesn't resume. Is there something else I should be doing within the application? Is there some method called I can leverage during preload? – eaglei22 Feb 10 '22 at 15:27