0

我们的ASP.NET MVC的网站使用CSS/JS捆绑(System.Web.Optimization版本1.1.3)。 - 我看到了我的捆绑文件过时,本地缓存的版本MVC缓存的精缩包并不能否定后,新版本

当我做一个发布后的第一个请求(>输入使用地址栏):我们为展开过程中遇到的问题。标头是:

dev tools cache directives

取而代之的是200我想有一个304响应,检查服务器上的实际文件确定是否缓存版本可以送达之前。有没有办法做到这一点,而不必使用像ctrl-f5或ctrl-r这样的特殊命令?

回答

0

创建这样一个属性:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] 
public sealed class NoCacheAttribute : ActionFilterAttribute 
{ 
    public override void OnResultExecuting(ResultExecutingContext filterContext) 
    { 
     filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); 
     filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false); 
     filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); 
     filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
     filterContext.HttpContext.Response.Cache.SetNoStore(); 

     base.OnResultExecuting(filterContext); 
    } 
} 

之后,你就可以把你的控制,以防止缓存的顶部。示例

[NoCache] 
public HomeController : Controller 
{ 
    // .... 
} 

或者只是在控制器上使用它。

[OutputCache(NoStore = true, Duration = 0)] 
相关问题