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.

The Solution

Setup

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:

image

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.

image

Configuration

IIS is all set but now you need to tell it which app pools and websites you want it to start. Simply go to:

C:\Windows\System32\inetsrv\config

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” />
</add>

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” />
</application>
</site>

Once again, add the highlighted text.

Validation

How do we know it works? That is easy…

  1. Open up the task manager and go to the processes tab.
  2. Sort by Image Name and find the process w3wp.exe. There may be multiple instances. The Username should be the name of the apppool.
  3. 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?
  4. To stop the process you must stop the application pool.
  5. 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?

Problem solved. Enjoy.

10 thoughts on “Auto Starting Websites on IIS 7.5

  1. I ended up with a corrupted XML file also. I think what may have caused it was when I copied the text from the website the quotes are a different format from quotes that you’d seen in a plain text file. Once I used the “plain” quotes. It worked fine

    Reply
  2. Pingback: How to speed up Sitefinity Website deployed on Windows Azure - Windows Azure Blog

  3. I tried this but adding the new config params didn’t work since it failed with following error:

    There was an error performing this application:

    Filename:
    \\?\C:\Windows\System32\inetsrv\config\applicationHost.config
    Line number: 146
    Error: Configuration file is not well-formed XML

    I thought config file got corrupted because I edited manually. But when I remove the new entries and save the file IIS is able to startup just fine.

    I am also running IIS 7.5 on Windows Server 2008 R2

    This seems to suggest IIS doesn’t like the new parameters? I have verified in the Configuration Editor the applicationIntilization section appears just fine. So the install of the new module seems to be OK.

    Any idea what’s wrong with the config file modification?

    Thanks.

    Reply
    • Actually, after another machine reboot somehow this started working. I can see the IIS preloading my application after an IIS Reset.
      The preload mechanism however is not triggered when a web.config update is made. Would have really liked that in this feature.

      -Siddharth.

      Reply
      • Hi Siddharth,

        I was wondering, have you ever succeeded (even with a workaround) to preload the app-pool when a web.config update is made? Has anyone every succeeded to?

        I’ve tried the “DisallowRotationOnConfigChange” configuration but seems to be irrelevant.

        Reply
    • I received same error: Configuration file is not well-formed XML

      Identified it was the wrong quotes. Update quotes and it will accept.

      Reply
  4. Big thanks!
    This works nice for me, except that the w3wc.exe was not running after Machine/IIS restart until the first request (which was fast).

    Reply
  5. Pingback: Dew Drop – June 5, 2013 (#1,561) | Alvin Ashcraft's Morning Dew

Leave a reply

required

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>