注销后,如果浏览器后退按钮按下,则返回上一个屏幕 [英] After logout if browser back button press then it go back last screen

查看:18
本文介绍了注销后,如果浏览器后退按钮按下,则返回上一个屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是第一次在 MVC 中开发解决方案,所以我面临一个大问题,当我从我的应用程序(mvc razor web 应用程序)注销时,它会显示登录页面,但是如果我按下浏览器后退按钮,它会显示最后一个屏幕,我不想要这个,我希望如果我按下后退按钮,它仍然显示相同的登录页面.这是我的注销代码

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 i press browser back button it displays last screen, i don't want this, i want if i press back button it still display same login page. here is my code for logout

public ActionResult Logout()
    {
        Session.Clear();
        Session.Abandon();
        Session.RemoveAll();

        FormsAuthentication.SignOut();


        this.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
        this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        this.Response.Cache.SetNoStore();          

        return RedirectToAction("Login");
    }

推荐答案

我前段时间遇到了这个问题,禁用整个应用程序的缓存解决了我的问题,只需将这些行添加到 Global.asax.cs 文件

I had this problem a while ago, disabling the cache for the entire application solved my problem, just add these line to the Global.asax.cs file

        protected void Application_BeginRequest()
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
            Response.Cache.SetNoStore();
        }

希望这会有所帮助.

这篇关于注销后,如果浏览器后退按钮按下,则返回上一个屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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