Automating IIs always running to auto start your application

Rick Strahl has an excellent article on how to configure IIS always running. He explains all the manual steps you have to do in order to do that. I’ll show you how to automate those steps. Usefull for example for azure cloudservices

Install Application Initialization Windows Feature

With this powershell, you install the feature “Application Initialization”.

Install-WindowsFeature -Name Web-AppInit

Set StartMode AlwaysRunning and PreloadEnabled

With this c# code you can create a small .exe to configure application initialization
You need to reference Microsoft.Web.Administration.dll located in %windir%\Windows\System32\inetsrv
There’s a nuget package with version from IIS7 that microsoft never updated anymore. I recommend to use the version you have installed.

 using (var serverManager = new ServerManager())
    var appPool = serverManager.ApplicationPools["YourAppPoolNameHere"];
    appPool.SetAttributeValue("startmode", "AlwaysRunning");
    appPool.SetAttributeValue("autostart", true);
    var site = serverManager.Sites["YourSiteNameHere"];
    // This code assumes that you have only one application
    site.Applications.First().SetAttributeValue("preloadEnabled", true);


And that’s it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s