IIS 8.5 - Application initialization not working
Asked Answered
A

5

14

I have installed Application Initialization, set the website's application pool Start Mode to "Always Running", and set Preload Enabled = "True" in the advanced settings of the website.

However, if I recycle the application pool manually and wait 10 seconds, when I then reload the website, I still have to wait another 10 seconds for the website to warm up. This indicates that the website is not starting.

Looking at task manager, I can see that the application pool is running the whole time - even after a recycle. However, the memory usage is very low until I make my own request to the website.

One thing I have noticed is that I do not have a "Start Automatically" setting in the advanced settings of my website as per this link: https://blogs.msdn.microsoft.com/vijaysk/2012/10/11/iis-8-whats-new-website-settings/

How can I get my application to auto-start?

Anaheim answered 18/2, 2016 at 11:49 Comment(2)
Did you ever get anywhere with this?Jenette
I did eventually. Everything has to be absolutely right for it to work, and the auto-start URL had to be a full controller and action reference (when working with MVC). I hope the answer I have just posted below helps you.Anaheim
A
27

It turned out to be a whole load of settings which all had to be correct. You go through all of the steps to install the relevant components and make the various config changes as per this link: http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization

The key part which was missing for me was an instruction in the Web.config as below. I had it going to just "/Login" which is a valid route, but as soon as I switched it to "/[Controller]/[Action]" it worked.

The advantage of this route is that you can create a custom action which will also hit the database (initialising Entity Framework), and perform any other slow initialisation you wish. For me, I just read a record out of a DB table, so I get ASP.NET auto-starting, and also save the few seconds it takes to warm up EF too :)

<system.webServer>
  <applicationInitialization doAppInitAfterRestart="true" skipManagedModules="false">
      <add initializationPage="/Login/WarmUp" />
    </applicationInitialization>
</system.webServer>
Anaheim answered 20/4, 2016 at 14:28 Comment(3)
Also note that if the site is configured to require SSL, initialization won't work. See IIS 7.5 Application Initialization Warm-up and HTTPS. Workaround: don't require SSL + URL Rewrite. See Application Initialization module fails when web site requires SSL; you'd typically replace localhost by the canonical name of your server.Anschluss
Adding the controller action didn't work for me. What's really strange having just the controller works on my coworker's machine. On my machine, it seems like app initialization module doesn't even get triggered when I recycle the app pool.Rounding
In my case I also had to set the option "Disable overlapped recycle" to "true" in application pool's advanced settingsMayes
B
10

Try Application Initialization setup:

I had similar issues and tried very hard with IIS 8.5 Windows Server 2012 R2. Everything in the IIS was set correctly after referring to so many sites however had missed the Application Initialization setup. Refer to the below link, Setup section.

enter image description here

https://www.iis.net/configreference/system.webserver/applicationinitialization

Blackout answered 19/3, 2016 at 13:5 Comment(1)
Even on Server 2019 this is an issue; without this being installed you'll get an error when websites start in IIS that PreloadEnabled is unrecognized.Thereinafter
I
8

These articles are very good:

Use IIS Application Initialization for keeping ASP.NET Apps alive

IIS 8.0 Application Initialization

However in my case there was a problem with installing the Application Initialization Role.

Check your IIS App's Modules listing. Ensure ApplicationInitializationModule is present.

enter image description here

I needed to uninstall/re-install this module.

I have no idea what happened as this appeared to work at first, then weeks later during development it stopped. No amount of tinkering/rework fixed it and I started to suspect I never actually saw this working.

Issue resolved upon uninstall/re-install Applicaion Initialization Module role.

Illustrational answered 31/7, 2017 at 15:19 Comment(2)
Where is this "Application Initialization Role"? I only see ApplicationInitializationModule...Rounding
For workstations: PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationInitMccabe
W
7

There are multiple .config locations where these settings can be set.

  1. Machine applicationHost.config (c:\windows\system32\inetsrv\Config)
  2. Website web.config (c:\inetpub\wwwroot for Default Web Site)
  3. Application web.config

I tried all but was only successful in configuring 3, the application web.config. My specific use case was calling a GET method on a WCF service.

The steps for application initialization are found in the other answers too. Here is one that was most helpful. IIS 8.0 Application Initialization

  1. Install the Windows feature Application Initialization (Web-AppInit)
  2. Set the IIS app pool Start mode = AlwaysRunning
  3. Set the IIS application Preload Enabled = true
  4. Add to the application web.config

    <system.webServer>     
        <applicationInitialization doAppInitAfterRestart="true" skipManagedModules="true">
            <add initializationPage="/Service.svc/Method/Parameter" />
        </applicationInitialization>
    </system.webServer> 
    
  5. Recycle app pool

  6. Check that the app initialized.

The thing I would like to point out is that the initialization page is relative to the application NOT to the root of the website/domain so if my absolute path is

domain.com/path1/path2/Service.svc

I would not include /path1/path2 in the initializationPage parameter.

Westmorland answered 11/4, 2019 at 1:37 Comment(1)
I followed the exact same steps and for some reason, when I recycle the app pool or restart IIS, this application initialization module is not hitting my controller. Not sure what I'm missing...Rounding
V
5

If anyone's wondering what to do in MVC when you have multiple areas to initialise, you need to put the area at the start, all within the root web.config file. I was stuck for a while trying to put it in the area's web.config. Also it's perfectly compatible with hybrid applications.

<add initializationPage="/NotMVC.aspx" />
<add initializationPage="/Area1/Controller/Action" />
<add initializationPage="/Area2/Controller/Action" />
Volans answered 18/4, 2018 at 1:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.