【发布时间】:2011-05-03 22:37:44
【问题描述】:
我正在开发一个 ASP.NET MVC 应用程序。大多数控制器操作不应该被缓存。因此,我在Application_BeginRequest 中输出无缓存标头:
protected void Application_BeginRequest()
{
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
}
应用程序在 IIS7 上运行,模块配置设置为 runAllManagedModulesForAllRequests="true"。这意味着所有静态文件也会通过请求管道(并禁用缓存)。
为这些静态文件启用缓存的最佳方法是什么?在Application_BeginRequest 中设置响应缓存标头之前是否必须检查扩展名,或者是否有更简单的方法(例如完全绕过静态文件的请求管道)?
【问题讨论】:
-
这看起来很有希望britishdeveloper.co.uk/2010/06/…
标签: c# .net asp.net-mvc caching iis