MVC 6-注销后防止缓存 [英] MVC 6 - Prevent Cache After Logout

查看:61
本文介绍了MVC 6-注销后防止缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVC 6,并且已经实现了Identity 3.0进行身份验证.

I'm using MVC 6 and I have implemented Identity 3.0 for authentication.

我正试图阻止用户注销后单击浏览器的后退按钮.我遇到的最接近的可行解决方案似乎在MVC 6中无法正常工作.

I'm trying to prevent the user from clicking on the browser back button after logout. The closest working solution I came across seems to be not working in MVC 6.

有人可以帮忙吗?

[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);
}
}

推荐答案

您可以使用它.


    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
    public sealed class NoCacheAttribute : ActionFilterAttribute
    {
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            filterContext.HttpContext.Response.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            filterContext.HttpContext.Response.Headers.Add("Pragma", "no-cache"); // HTTP 1.0.
            filterContext.HttpContext.Response.Headers.Add("Expires", "-1"); // Proxies.

            base.OnResultExecuting(filterContext);
        }
    }

这篇关于MVC 6-注销后防止缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆