通过powershell在IIS上设置文件的html响应标头缓存控制



我正在尝试在IIS上的HTTP响应标头上设置CACHE-CONTROL:max-age到特定文件。我正在尝试使用PowerShell脚本或CMD命令来做到这一点。我可以做吗?如果是,如何?

为时已晚,无法回答这个问题,可能对仍在寻找解决方案的人有帮助。

我在powershell中使用了" appcmd.exe"。以下是我在PowerShell中使用的方式:

# path to appcmd.exe
$appCmd = "C:windowssystem32inetsrvappcmd.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 to to and and addd custom headers conconvert conconvert 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

最新更新