IIS 7 强制刷新图像

IIS 7 Force Fresh Images(IIS 7 强制刷新图像)
本文介绍了IIS 7 强制刷新图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何强制 IIS 7缓存特定页面的图像?

How do I force IIS 7 to not cache images for a particular page?

推荐答案

在 IIS7 中,您可以在 web.config 中以声明方式或以编程方式执行此操作.

In IIS7, you can do this either declaratively in your web.config, or programmatically.

<location path="YourPath">
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="DisableCache" />
    </staticContent>
  </system.webServer>
</location>

编程解决方案需要一个简单的 HttpModule,它已注册为在集成模式下运行所有​​请求,您可以在其中查找您关心的 URL.然后调用:

The programmatic solution requires a simple HttpModule that's registered to run for all requests in Integrated mode, where you look for the URLs that you're concerned about. Then call:

context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

FWIW,您可能需要考虑仅禁用客户端缓存,同时启用服务器端缓存,方法是使用 HttpCacheability.ServerAndNoCache.此外,如果您在图像名称上添加查询字符串,您将阻止 http.sys 进行服务器端缓存.

FWIW, you may want to consider disabling client-side caching only, while enabling server-side caching, by using HttpCacheability.ServerAndNoCache. Also, if you add a query string on the image names, you will prevent server-side caching by http.sys.

如果有帮助,我会在我的书中详细介绍这些技术:Ultra-Fast ASP.NET.

In case it helps, I cover techniques like these in detail in my book: Ultra-Fast ASP.NET.

这篇关于IIS 7 强制刷新图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)