升级到 Play Framework 2.5.4,Scala 后会话不起作用
Session doesn't work after upgrade to Play Framework 2.5.4, Scala
将我的项目从 2.4.8 升级到 Play Framework 2.5.4 后,我在使用会话时遇到问题。我的控制器中有一些方法可以测试问题:
def test = Action { implicit request =>
Redirect(controllers.routes.Carts.test2()).withSession(new Session(Map("user" -> "customer")))
}
def test2 = Action { implicit request =>
Ok(request.session.data.toString())
}
基本上 test
方法添加会话并重定向到 test2
方法。当我在重定向后使用测试方法 url 打开页面时,我在浏览器中得到了我需要的东西:
Map(user -> customer)
但是如果我在那之后刷新页面,我会得到:
Map(csrfToken ->
ce1a6222484f378d38ab3534c2b400191270395d-1470238791014-c988ce3fe47259173166949a)
因此,会话似乎仅适用于一个请求,然后被 csrfToken 覆盖。我已经禁用了所有过滤器。我的 class 过滤器看起来像这样:
class Filters @Inject() () extends HttpFilters {
val filters = Seq.empty
}
无法理解我的代码有什么问题。相同的代码在升级前工作正常。
检查你的 application.conf 如果 session.secure 是真的把它带到
play.http.session.secure=false
将我的项目从 2.4.8 升级到 Play Framework 2.5.4 后,我在使用会话时遇到问题。我的控制器中有一些方法可以测试问题:
def test = Action { implicit request =>
Redirect(controllers.routes.Carts.test2()).withSession(new Session(Map("user" -> "customer")))
}
def test2 = Action { implicit request =>
Ok(request.session.data.toString())
}
基本上 test
方法添加会话并重定向到 test2
方法。当我在重定向后使用测试方法 url 打开页面时,我在浏览器中得到了我需要的东西:
Map(user -> customer)
但是如果我在那之后刷新页面,我会得到:
Map(csrfToken -> ce1a6222484f378d38ab3534c2b400191270395d-1470238791014-c988ce3fe47259173166949a)
因此,会话似乎仅适用于一个请求,然后被 csrfToken 覆盖。我已经禁用了所有过滤器。我的 class 过滤器看起来像这样:
class Filters @Inject() () extends HttpFilters {
val filters = Seq.empty
}
无法理解我的代码有什么问题。相同的代码在升级前工作正常。
检查你的 application.conf 如果 session.secure 是真的把它带到
play.http.session.secure=false