New API to avoid restarting IIS when you add a new app pool (Windows Server 2008, RC0)

One of the things we worked hard on in IIS7 was eliminating unnecessary restarts of IIS in daily operations of the Web server. In the recent RC0 release of Windows Server 2008 RC0, we added an API for folks who want to automate flushing the token cache on IIS7. This might be something that you would want to do if you change settings that would change properties of the token after it is cached. Before RC0, that would require restarting IIS. With this new API, you can automate flushing the token cache without restarting IIS7.

 

Here's a sample for how to use the new API:

var adminManager = new ActiveXObject( "Microsoft.ApplicationHost.AdminManager" );
var appPoolsElement = adminManager.GetAdminSection( "system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST" );var defaults = appPoolsElement.ChildElements.Item("applicationPoolsControl");
var flush = defaults.Methods.Item("FlushTokenCache").CreateInstance();flush.Execute();

 One additional note: After flushing the token, you should recycle all the worker processes affected, else the setting won’t take effect (i.e. IIS can’t change the worker process token on an already running worker process).  To do this, call the apppool.recycle property; check out this example in another article on IIS.NET for a sample on using that property.


1 Comment

  • Here is a managed code example to accomplish the same:

    using (ServerManager serverManager = new ServerManager())
    {
    serverManager.ApplicationPools.ChildElements["applicationPoolsControl"].Methods["FlushTokenCache"].CreateInstance().Execute();
    }

Comments have been disabled for this content.