【问题标题】:Browser back button is showing previous page after logout in Grails在 Grails 中注销后,浏览器后退按钮显示上一页
【发布时间】:2020-02-16 20:53:43
【问题描述】:

我正在使用 grails-2.4.5 版本和 spring-security-core-2.0-RC5。我在 config.groovy 页面中设置了默认目标 URI。当用户登录时,他们可以访问该页面,当注销无法访问时,应该只显示登录页面。

我的问题是,当显示用户注销登录页面时,但如果点击浏览器后退按钮,则会显示默认目标页面,尽管他无法访问任何操作。但这很奇怪。我的配置如下:

在 config.groovy >>

grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/dashboard/index'    
grails.plugin.springsecurity.logout.postOnly = false

我的url映射类>>

    class UrlMappings {

    static mappings = {
        "/$controller/$action?/$id?(.$format)?"{
            constraints {
                // apply constraints here
            }
        }

        "/"(controller:"login", action: "auth")
        "500"(view:'/error')
    }
}

我的默认目标 uri 方法 >>

    class DashboardController {

    def index() {
    }
}

【问题讨论】:

  • 后退按钮会显示上一页,因为浏览器缓存了它。
  • @Amiy怎么解决
  • 您可以将标头添加到非缓存并重新验证,请参阅this answer。有关详细信息,请参阅this post
  • @Amiy 已经尝试过这个答案,没有运气
  • 如果您尝试了一些新的东西,那么请将其添加到问题中。

标签: grails spring-security


【解决方案1】:

有很多可能的停止方式,

浏览器后退按钮在注销后显示上一页

  • 使用 JavaScript,您可以清除位置历史记录或禁用返回按钮。

    <script>
    history.pushState(null, null, location.href);
    window.onpopstate = function () {
        history.go(1);
    };
    </script>
    

Demo

Here你会得到很多可能的选择

希望对你有帮助。

【讨论】:

  • 我使用的是 2.4.5 版本。但该文档适用于 4.0.0。是否可以在我的版本中使用 AuthInterceptor?如果是这样,那么一些例子会很好
  • 据我了解,这仅在将任何请求传递给控制器​​时才有效,但是当我单击浏览器后退按钮时,不会调用任何操作,只显示缓存的视图。我想在那里显示登录页面。
  • 哦,那么,使用 JavaScript 的最佳方式
  • 谢谢,我稍后会测试并让您的答案被接受。
猜你喜欢
  • 2012-07-09
  • 1970-01-01
  • 1970-01-01
  • 2015-04-21
  • 1970-01-01
  • 2022-01-09
  • 2015-09-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多