简体   繁体   English

注销后C#ASP.NET MVC后退按钮问题

[英]C# ASP.NET MVC Back button issue after logout

I am working on a logout method for an MVC application and I ran into a problem. 我正在为MVC应用程序开发注销方法,但遇到了问题。 Every time I logout, the application checks the user authentication and returns them to the login page. 每次注销时,应用程序都会检查用户身份验证,并将其返回到登录页面。

Logout method: 登出方法:

[HttpGet]
    [CustomAuthorize]
    public ActionResult Logout()
    {            
        //Response.Cache.SetExpires(DateTime.Now);
        FormsAuthentication.SignOut();
        Session.Clear();
        Session.Abandon();
        Session.RemoveAll();
        return RedirectToAction("Index", "Home");
    }

The pages used after loging in all have the [CustomAuthorize] attribute. 登录后使用的所有页面均具有[CustomAuthorize]属性。

Using MS Edge browser, if I click the Back button, the program goes through the CustomAuthorize method and if the user is logged out, it just returns them to the Login page as intended. 使用MS Edge浏览器,如果我单击“上一步”按钮,程序将通过CustomAuthorize方法,如果用户已注销,则仅将其按预期返回到“登录”页面。

However, if I use any other browser (Chrome, Firefox), pressing the Back button just goes back to the previous page where I pressed the Logout button without even going through the CustomAuthorize to check the Authorization. 但是,如果我使用任何其他浏览器(Chrome,Firefox),则按“后退”按钮仅返回上一页面,在此我按了“注销”按钮,甚至没有通过CustomAuthorize来检查授权。

What could be the cause for this and what could be a possible solution to resolve this issue? 这可能是什么原因,以及解决该问题的可能解决方案是什么?

If any more information is needed, just let me know. 如果需要更多信息,请告诉我。

Thank you. 谢谢。

Justas 就像

you need to disable caching globally 您需要全局禁用缓存

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC 注销和返回按钮 - ASP.NET MVC logout and back button 单击后退按钮时,注销后页面仍显示 asp.net mvc 3 - Page still shows after logout when back button is clicked asp.net mvc 3 如何防止用户在启用了缓存的asp.net mvc中注销后单击返回按钮 - How to prevent user to click on the back button after logout in asp.net mvc with cache enabled 如何在 ASP.NET Core MVC 3.1 应用程序中注销后防止返回按钮 - How to prevent back button after logout in ASP.NET Core MVC 3.1 app asp.net注销中浏览器问题的后退按钮 - back button of browser issue in asp.net logout 当用户在 asp.net c# 中注销时如何禁用浏览器中的后退按钮 - How to disable the back button in browser when user logout in asp.net c# 网页URL带来已经注销的页面:asp.net c#(不是返回按钮,而是页面url) - webpage URL bringing the page which is already logout :asp.net c# (Not back button, but the page url) 注销后,如何在ASP.NET MVC3中单击浏览器的后退按钮时将用户重定向到登录页面 - After logout,how to redirect user to login page when he/she will click back button of browser in ASP.NET MVC3 ASP.NET MVC 2:什么是MVC更像编码这个C#“后退”按钮的方式? - ASP.NET MVC 2: What's a more MVC like way to code this C# “Back” button? 将值从Button传递回ASP.NET MVC 3 Razor页面的C#控制器 - Pass Value from Button back to C# Controller from ASP.NET MVC 3 Razor Page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM