in C#/Powershell - Is it possible to change the Idle TimeOut for an IIS Application Pool?

前端 未结 8 526
别那么骄傲
别那么骄傲 2021-02-05 08:29

I want to disable the idle timeout (Set it to Zero) of an application pool and I want to perform this at setup time, is it possible to perform this action from C# or PowerShell?

8条回答
  •  被撕碎了的回忆
    2021-02-05 09:17

    Here is a complete Powershell sample showing how to create an application pool (for ASP.NET Core) and set many of its values:

    Import-Module WebAdministration
    
    $appPoolName     = "MyWebPool"
    $appPoolFullName = "IIS:\AppPools\$appPoolName"
    
    if(!(Test-Path $appPoolFullName)) {
        New-WebAppPool $appPoolName -Force
    
        Set-ItemProperty $appPoolFullName -Name managedPipelineMode -Value Integrated
        Set-ItemProperty $appPoolFullName -Name managedRuntimeVersion -Value "" # means "No Managed Code"
        Set-ItemProperty $appPoolFullName -Name startMode -Value AlwaysRunning
    
        $3_days = New-TimeSpan -Days 3
        Set-ItemProperty $appPoolFullName -Name processModel.idleTimeout -Value $3_days
        Set-ItemProperty $appPoolFullName -Name processModel.identityType -Value NetworkService
        Set-ItemProperty $appPoolFullName -Name processModel.idleTimeoutAction -Value Suspend
    
        $zero_ts = New-TimeSpan
        Set-ItemProperty $appPoolFullName -Name recycling.periodicRestart.time -Value $zero_ts
    }
    

提交回复
热议问题