Disable IIS Idle Timeouts in Azure Web Role

Albert Bori picture Albert Bori · Aug 6, 2013 · Viewed 7.9k times · Source

To prevent AppPool recycling every 20 minutes, I'd like to remove IIS AppPool Idle Timeouts when my Azure Web Role starts. My website is a Web Application Project.

How do I do this?

Answer

Edward Brey picture Edward Brey · Dec 11, 2013

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>