In trying to set this up, I kept finding articles and blog posts that had instructions that didn’t work. In the end, setting this up was pretty easy.
First off, I am running IIS 7.5 on Windows Server 2008 R2. If you have a different set up, this might not work for you.
First, the problem – a pretty common one:
We’ve got our Application Pools set to recycle once a day. However, each time the app pool recycles the first user to hit the site has to wait while everything warms up again. That wait can be 30 seconds or so which is a pretty long time. So I want my application to be ready all the time, even after an Application Pool reset.
Side note… I don’t recommend using the default settings for app pool recycling. If you do, the pool will recycle every 1740 minutes. However, that time could end up being in the middle of a busy day. That would be bad. Instead, I set mine to recycle at around 3 AM when no one is using my site. Of course, you may have different needs.
IIS 7.5 has a feature called Application Initialization. I’ve seen many blog posts about it. Some say you can use the GUI to configure it. Some say you configure it via a .config file. Most of them imply that the feature is there and ready to be used. For me it was not installed by default and there was no GUI. I’m not sure why. Are my servers (prepared by a different team) configured to not have this feature? I don’t know.
In any case, installing this feature is easy. Just go here and install the Application Initialization Module for IIS 7.5. It is pretty quick but will require a reboot.
Once you do, open IIS and click on the server node and in the main window under Management, click on Configuration Editor:
Inside the editor, set the section (via the dropdown at the top) to “system.webServer/applicationInitialization”. If you can do that, the installation was successful! Prior to installing, that node wasn’t there! Interestingly, there are some settings here that imply you can change them via the UI. For instance, I tried setting “doAppInitAfterRestart” to True. Not only did that not help, it caused errors with IIS. So why is it there? I have no idea. My advice… don’t touch those settings.
IIS is all set but now you need to tell it which app pools and websites you want it to start. Simply go to:
and open the applicationHost.config file. You may want to back the file up before you make changes.
You’ll need to add two things.
1. The App Pool:
Find the applicationPools node. Within it it you will find each app pool listed. Here is an example:
<add name=”YOURAPPNAMEHERE” autoStart=”true” managedRuntimeVersion=”v4.0″ startMode=”AlwaysRunning”>
<processModel identityType=”ApplicationPoolIdentity” loadUserProfile=”true” />
<recycling logEventOnRecycle=”Time, Requests, Schedule, Memory, IsapiUnhealthy, OnDemand, ConfigChange, PrivateMemory” />
Simply add the highlighted text startMode=”AlwaysRunning”. You will note that it probably already says autoStart=”true” but yet it didn’t autostart. Another misleading part of this, huh? Oh well.
2. The Web Site
Go to the sites node and find your site which will look something like this:
<site name=”YOURSITENAMEHERE” id=”4″ serverAutoStart=”true”>
<application path=”/” applicationPool=”YOURAPPPOOL” preloadEnabled=”true”>
<virtualDirectory path=”/” physicalPath=”C:\inetpub\wwwroot\YOURSITENAME” />
Once again, add the highlighted text.
How do we know it works? That is easy…
- Open up the task manager and go to the processes tab.
- Sort by Image Name and find the process w3wp.exe. There may be multiple instances. The Username should be the name of the apppool.
- If you try to End the Process, you will find that it restarts itself. Seems like it won’t go away ever. Uh oh, how do you stop it then?
- To stop the process you must stop the application pool.
- Of course, if you restart the app pool you will find that the w3wp process comes back. But wasn’t that what you wanted in the first place?