28 August 2015

c# : programatically disable IIS AppPool Recycling

using System;
using System.Text;
using Microsoft.Web.Administration;
using System.Linq;

internal static class Sample
{
    private static void Main(string[] args)
    {
        using (ServerManager serverManager = new ServerManager())
        {
            foreach (var ap in serverManager.ApplicationPools)
            {
               ap.Recycling.PeriodicRestart.Time = TimeSpan.Zero;
            }

            serverManager.CommitChanges();
        }
    }
}