【问题标题】:Trying to Programmatically Expire the HTTP Response Headers尝试以编程方式使 HTTP 响应标头过期
【发布时间】:2012-06-11 20:29:06
【问题描述】:

我们的团队正在构建一个带有 Silverlight 模块的 C# 项目。我们部署到带有 IIS 7 的 Windows 2008。我正在尝试以编程方式立即使与名为 ClientBin 的文件夹关联的 HTTP 响应标头过期。我知道如何通过 IIS 管理器手动完成。 (基本上,我会转到感兴趣的文件夹或文件的 HTTP Response Headers 部分,然后使用“Set Common Headers....”立即过期。)但是,我们将重新部署到 IIS 中的一些时间,我想确保它以编程方式完成,因为一直保持重新配置是一件令人头疼的事情。

我应该从项目的 C# 代码中执行此操作,还是使用 WMI 脚本执行此操作更好?

【问题讨论】:

    标签: silverlight iis-7 http-headers wmi cache-expiration


    【解决方案1】:

    @kev 和 @jeff-cuscutis 提供了使用 ASP.NET 应用程序的 web.config 文件中的 XML 配置来配置 HTTP 响应标头过期的方法

    How to configure static content cache per folder and extension in IIS7?

    您可以在根 web.config 中为整个文件夹设置特定的缓存头:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <configuration>
    
    <!-- Note the use of the 'location' tag to specify which 
    
       folder this applies to-->
    
    <location path="images">
    
    <system.webServer>
    
      <staticContent>
    
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
    
      </staticContent>
    
    </system.webServer>
    
    </location>
    
    </configuration>
    

    或者您可以在内容文件夹中的 web.config 文件中指定这些:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <configuration>
    
    <system.webServer>
    
    <staticContent>
    
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
    
    </staticContent>
    
    </system.webServer>
    
    </configuration>
    

    我不知道针对特定文件类型的内置机制。

    您可以在每个文件的基础上执行此操作。使用路径属性包含文件名

    <?xml version="1.0" encoding="UTF-8"?>
    
    <configuration>
    
    <location path="YourFileNameHere.xml">
    
        <system.webServer>
    
            <staticContent>
    
                <clientCache cacheControlMode="DisableCache" />
    
            </staticContent>
    
        </system.webServer>
    
    </location>
    
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      • 2020-01-16
      • 2016-04-06
      • 2013-12-02
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      相关资源
      最近更新 更多