Disable IIS Idle Timeouts in Azure Web Role Disable IIS Idle Timeouts in Azure Web Role azure azure

Disable IIS Idle Timeouts in Azure Web Role


Create a startup task to disable the idle timeout:

  1. In the website project referenced by your web role project, add a file Startup.cmd to the root folder.

  2. In the properties for Startup.cmd, set Copy to Output Directory to Copy if newer.

  3. Add this line to Startup.cmd:

    if exist %windir%\system32\inetsrv\appcmd.exe %windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00

    The if exist %windir%\system32\inetsrv\appcmd.exe qualifier is optional. It lets you use the same code on the Azure Emulator Express, so you don't need IIS installed or need to run Visual Studio as Administrator.

  4. Save the file as UTF-8 without signature. (File > Advanced Save Options in Visual Studio.)

  5. In your web role project, in ServiceDefinition.csdef, add this to the WebRole:

    <Startup>  <Task commandLine="Startup.cmd" executionContext="elevated" /></Startup>


Another option is to configure IIS Idle Time-Out Action to 'Suspend'. You can do it as a part of your web role startup script.

Command that you need is on the box as part of IIS setup (note that this will work with Windows Server 2012 R2 and up, with your code targeting .NET 4.5.1 framework and higher).

%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeoutAction:Suspend

You'll have to update your Azure Cloud Service configuration file (.cscfg) to use OS Family 4, as outlined by scottgu in his blog post.

Since startup actions run when your instances are provisioned and before web application is deployed to IIS, by setting application pool defaults will defacto set your application apppool idel time out action to Suspend.


In the root of your Web Application Project, create a file named WebRole.cs with the following code:

public class WebRole : RoleEntryPoint{    public override void Run()    {        RemoveIISTimeouts();        base.Run();    }    private void RemoveIISTimeouts()    {        Process.Start(            String.Format(@"{0}\system32\inetsrv\appcmd", Environment.GetEnvironmentVariable("windir")),            "set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00");    }}