You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用PowerShell设置IIS<clear>元素?父级配置位置咨询

IIS应用池定期重启配置问题排查

我们在部署IIS应用时,使用PowerShell命令Clear-ItemProperty IIS:\AppPools\$name -Name Recycling.periodicRestart.schedule清除应用池的periodicRestart计划。这个操作在大部分服务器上都能正常生效,但在一台无法直接访问的服务器上,应用仍会每日定时重启。而通过IIS UI清除计划后,问题就解决了。

对比applicationHost.config的配置差异:

  • 脚本执行后的配置:
<recycling>
    <periodicRestart time="00:00:00">
    </periodicRestart>
</recycling>
  • UI操作后的配置:
<recycling>
    <periodicRestart time="00:00:00">
        <schedule>
            <clear />
        </schedule>
    </periodicRestart>
</recycling>

根据文档说明,<clear />元素的作用是从当前层级配置中移除父级配置设置,推测这台服务器存在继承自父级的定期重启配置。

Q1:是否可以用PowerShell设置该<clear />元素?

可以。Clear-ItemProperty无法生成<clear />节点,需要使用专门的IIS配置命令来实现:

  • 使用Clear-WebConfiguration命令,该命令会自动生成<clear />节点以清除继承的配置:
Clear-WebConfiguration "/system.applicationHost/applicationPools/add[@name='$name']/recycling/periodicRestart/schedule"
  • 也可以用Set-WebConfiguration手动添加<clear />元素:
Set-WebConfiguration "/system.applicationHost/applicationPools/add[@name='$name']/recycling/periodicRestart/schedule" -Value @{clear=''}

Q2:该父级配置可能存放在何处?

父级配置通常存在以下几个位置:

  • 服务器全局applicationHost.config:路径为C:\Windows\System32\inetsrv\config,文件中的<applicationPoolDefaults>节点会定义所有应用池默认继承的配置,包括定期重启计划。
  • applicationHost.config中的通用应用池配置:如果在<applicationPools>节点下有未指定特定应用池的全局规则,也会被所有应用池继承。
  • 站点/应用级web.config:极少数情况下,站点或应用目录下的web.config中可能包含应用池相关的继承配置,但这种场景比较少见,应用池配置通常集中在applicationHost.config中。

内容的提问来源于stack exchange,提问作者Andy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 05:05:15