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

标签 http iis header max response

我正在尝试将 IIS 上的 http 响应 header 上的 cache-control: max-age 设置为特定文件。我正在尝试使用 PowerShell 脚本或 CMD 命令来执行此操作。我可以这样做吗?如果是,怎么办?

最佳答案

来不及回答这个问题,可能对那些仍在寻找解决方案的人有帮助。

我在 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

关于http - 通过powershell在IIS上设置文件html响应头缓存控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40884327/

相关文章:

python - 防止下载过大的文件

wcf - iis 托管 WCF 服务时 Log4Net 不写入

asp.net - Response.TrySkipIisCustomErrors不起作用

c# - Wcf 休息服务 URL 最大长度

c - 如何在c中读取TIFF文件头?

ruby-on-rails - Rails ActiveResource 检测 HTTP 206 响应代码

node.js - node.js 应该监听哪些端口?如何以及为什么?

perl - 如何在 Perl 中获取 HTTP 状态和 Location header ?

css - Prestashop 编辑标题 css

php - 如何调试仅在(谷歌)机器人请求页面时发生的问题?