相关疑难解决方法(0)

如何关闭MVC请求的缓存,而不是IIS7中的静态文件?

我正在开发一个ASP.NET MVC应用程序.大多数控制器操作都不应该被缓存.因此我输出no-cache标头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();
    }
Run Code Online (Sandbox Code Playgroud)

应用程序在IIS7上运行,并带有模块配置设置runAllManagedModulesForAllRequests="true".这意味着所有静态文件也会通过请求管道(并禁用缓存).

为这些静态文件启用缓存的最佳方法是什么?在设置响应缓存标头之前是否必须检查扩展?Application_BeginRequest或者是否有更简单的方法(例如完全绕过静态文件的请求管道)?

.net c# iis asp.net-mvc caching

6
推荐指数
1
解决办法
2512
查看次数

标签 统计

.net ×1

asp.net-mvc ×1

c# ×1

caching ×1

iis ×1