代码之家  ›  专栏  ›  技术社区  ›  TAG

如何设置IIS中静态文件的可访问性?

  •  3
  • TAG  · 技术社区  · 16 年前

    我有一些静态图像在我的基于IIS6的网站上的一个文件夹中,我希望尽可能少的下载(以保留带宽)。我已将内容过期设置为30天后过期。在IIS中,我还能做些什么来尝试通过浏览器、代理和网关缓存最大化缓存吗?

    例如添加缓存控制头?还有别的吗?

    2 回复  |  直到 13 年前
        1
  •  1
  •   Galin Iliev Mischa Kroon    13 年前

    http://www.galcho.com/Blog/post/2008/02/27/IIS7-How-to-set-cache-control-for-static-content.aspx

    这是一篇包含以下内容的博客文章:

    1. 允许重写静态内容设置
    2. 使用以下命令设置缓存设置
    3. 在客户端缓存它
        2
  •  1
  •   Community CDub    8 年前

    以下是我对这个问题的回答: "Expires" in http header for static content? how-to

    @ECHO OFF 
    REM ---------------------------------------------------------------------------
    REM Caching - sets the caching on static files in a web site
    REM syntax 
    REM     Caching.CMD 1 d:\sites\MySite\WWWRoot\*.CSS
    REM 
    REM   %1 is the WebSite ID
    REM   %2 is the path & Wildcard - for example, d:\sites\MySite\WWWRoot\*.CSS
    REM   _adsutil is the path to ADSUtil.VBS
    REM ---------------------------------------------------------------------------
    
    SETLOCAL
    REM *******
    REM SET THIS TO POINT TO adsutil.vbs - TYPICALLY c:\inetpub\adminscripts\adsutil.vbs
    REM *******
    SET _adsutil=D:\Apps\Scripts\adsutil.vbs
    
    FOR %%i IN (%2) DO (
      ECHO Setting Caching on %%~ni%%~xi
      CSCRIPT %_adsutil% CREATE W3SVC/%1/root/%%~ni%%~xi "IIsWebFile"
      CSCRIPT %_adsutil% SET    W3SVC/%1/root/%%~ni%%~xi/HttpExpires "D, 0x69780"
      ECHO.
    )
    

    它将Web根目录中每个CSS文件的缓存值设置为5天,然后按如下方式运行:

    Caching.CMD 1 \site\wwwroot\*.css
    Caching.CMD 1 \site\wwwroot\*.js
    Caching.CMD 1 \site\wwwroot\*.html
    Caching.CMD 1 \site\wwwroot\*.htm
    Caching.CMD 1 \site\wwwroot\*.gif
    Caching.CMD 1 \site\wwwroot\*.jpg
    

    有点痛苦,但可行。

    btw-要获取httpExpires的值,请在GUI中设置该值,然后运行

    AdsUtil.vbs ENUM W3SVC/1/root/File.txt
    

    为了得到你需要的实际价值