【问题标题】:Set file's html reponse headers cache-control on IIS via powershell通过powershell在IIS上设置文件html响应头缓存控制
【发布时间】:2016-11-30 09:15:46
【问题描述】:

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

【问题讨论】:

    标签: http iis header max response


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 2018-04-29
      • 2023-03-15
      • 2023-04-09
      相关资源
      最近更新 更多