【发布时间】:2016-11-30 09:15:46
【问题描述】:
我正在尝试将 IIS 上的 http 响应标头上的 cache-control: max-age 设置为特定文件。我正在尝试使用 PowerShell 脚本或 CMD 命令来执行此操作。我可以这样做吗?如果是,怎么做?
【问题讨论】:
标签: http iis header max response
我正在尝试将 IIS 上的 http 响应标头上的 cache-control: max-age 设置为特定文件。我正在尝试使用 PowerShell 脚本或 CMD 命令来执行此操作。我可以这样做吗?如果是,怎么做?
【问题讨论】:
标签: http iis header max response
回答这个问题为时已晚,可能对仍在寻找解决方案的人有所帮助。
我在 Powershell 中使用了“appcmd.exe”。 以下是我在 Powershell 中的使用方式:
# path to appcmd.exe
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe"
# Path to the folder where we want to set the cache max-age
# in this case its a "scripts" folder in "Default Web Site" site
$env:folderPathScripts = "Default Web Site/scripts"
# sets the max age to 2 days
& $appCmd --% set config "%folderPathScripts%" -section:staticContent -clientCache.cacheControlMode:UseMaxAge -clientCache.cacheControlMaxAge:2.00:00:00
或
#To disable the cache
& $appCmd --% set config "%folderPathScripts%" -section:staticContent -clientCache.cacheControlMode:DisableCache
我参考了以下链接:
https://forums.iis.net/t/1174801.aspx?How+to+Remove+and+Add+custom+headers+convert+from+appcmd
https://technet.microsoft.com/en-us/library/jj635852(v=ws.11).aspx
https://technet.microsoft.com/en-us/library/cc770661(v=ws.10).aspx
【讨论】: