After logout if browser back button press then it go back last screen

前端 未结 6 1782
执念已碎
执念已碎 2020-12-13 09:58

Hello I am developing a solution in MVC in first time so I am facing a big issue, When I logout from my application(mvc razor web application) it displays login page, but if

6条回答
  •  萌比男神i
    2020-12-13 10:40

    You need to add the cache META Tag for all the last page you visited

    So add this for all the pages, by making a CustomAttribute like [NoCache] and decorate

    public 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.SetCacheability(HttpCacheability.NoCache);
            filterContext.HttpContext.Response.Cache.SetNoStore();
    
            base.OnResultExecuting(filterContext);
        }
    }
    
    
    public class AccountController : Controller
    {
        [NoCache]
        public ActionResult Logout()
        {
            return View();
        }
    }
    

    Or try it with javascript on the page like

    
    
    
    

提交回复
热议问题