注销后防止后退操作

注销后防止后退操作

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

问题描述

注销后,如果我按浏览器中的后退"按钮,则该页面不应显示上一页,而必须转到默认页面(仅登录页面).

After logout if i press the back button in the browser, it should not show the previous page, it has to go to default page (login page only).

因此,我尝试了多种方式(ruby on rails应用程序),例如"history.forward()","onbeforeunload",使元标记中的缓存过期,"http://www.brookebryan.com/后退按钮检测"这么多..我很困惑.

So i have tried in many ways(ruby on rails application) like "history.forward()" ,"onbeforeunload", expire cache in meta tag, "http://www.brookebryan.com/ back button detection" so many .. i am very confused.

有人可以提出解决方案吗?

can anyone suggest a solution?

推荐答案

您需要做的就是禁用浏览器缓存,以便从页面注销后它不会返回缓存的页面.您可以通过设置响应标题来避免在应用程序控制器中进行缓存.怎么样?

What you have to do is disable the browser-caching so that it wont return the cached page after you logout from the page. You can do that by setting the response-header to avoid caching in application controller. How?

in 'application_controller.rb' .....

before_filter :set_no_cache

def set_no_cache
  response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
  response.headers["Pragma"] = "no-cache"
  response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end

如本答案所述: https://stackoverflow.com/a/748646

这篇关于注销后防止后退操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:56