【问题标题】:Scala Play Framework Discarding Cookies questionsScala Play Framework Discarding Cookies 问题
【发布时间】:2016-11-10 14:58:26
【问题描述】:

您好,我在使用 Play Framework for Scala 中的 Discarding Cookies 功能时遇到了一些问题

我使用域 x.y.z.com 设置 cookie 我试图丢弃 cookie,但我创建的 DiscardingCookie 具有相同的名称,但域设置为 y.z.com。饼干会被丢弃吗?或者域是否需要 100% 匹配并且不能在子域上工作才能丢弃 cookie。

另外,如果我在 abc.com 上设置了一个 cookie,但被定向到该 cookie 不存在的另一个页面,但随后从新的重定向,进行 DiscardingCookie 调用以丢弃不再存在的 cookie,该 cookie 会不会一旦我返回 abc.com 就会被丢弃?或者该 cookie 是否超出范围,因为我不再在正确的域上

【问题讨论】:

    标签: java scala cookies playframework playframework-2.0


    【解决方案1】:

    DiscardingCookie 案例类定义如下:

    /**
     * A cookie to be discarded.  This contains only the data necessary for discarding a cookie.
     *
     * @param name the name of the cookie to discard
     * @param path the path of the cookie, defaults to the root path
     * @param domain the cookie domain
     * @param secure whether this cookie is secured
     */
    case class DiscardingCookie(name: String, path: String = "/", domain: Option[String] = None, secure: Boolean = false) {
      def toCookie = Cookie(name, "", Some(-86400), path, domain, secure)
    }
    

    如您所见,有一个domain 参数。只需将其设置为 Some("x.y.z.com") 即可。

    【讨论】:

      猜你喜欢
      • 2013-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-30
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多