在 ASP.NET 中没有为特定页面设置缓存?

Set no cache in ASP.NET for specific page?

我想将我的 MVC 5 应用程序设置为不缓存我的登录视图的页面(即,如果我的用户在浏览器中按下 'Back',我希望登录视图实际重新加载以便导航至登录页面)。

这样我就可以在用户尝试以其他人身份登录之前注销当前用户。

我在 Global.asax 中看到有人使用它的示例:

protected void Application_BeginRequest()
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
    Response.Cache.SetNoStore();
    Response.Cache.SetProxyMaxAge(new TimeSpan(0, 0, 0));
    Response.Cache.SetValidUntilExpires(false);
    Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
}

但这基本上停止了对每个请求的每个页面的缓存。 我相信有一种方法可以通过路由或过滤器来做到这一点?也许是方法注释?谁能解释一下?

为什么不将这些属性添加到您的操作中:

[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)] 

示例:

public class MyController : Controller
{
    [OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)] 
    // will disable caching for Index only
    public ActionResult Index()
    {
       return View();
    }
}