我正在开发一个支持各种子域的rails应用程序。存在诸如example.com的根域,并且用户通过它登录,然后将用户重定向到特定的子域url、group.example.com,并且用户可以根据他们访问的组在子域url之间跳转。如何在会话cookie中设置域属性,使其在子域(ex2.example.com和ex3.example.com)之间不可用?
编辑:
我很抱歉我指的是会话cookie。我想发送不同的cookie为每个子域的网址。
发布于 2015-09-02 14:37:20
请看一下Cookie类的文档。您可以在创建/删除cookie时指定域。
cookies[:name] = {
value: 'a yummy cookie',
domain: 'ex2.example.com'
}当然,可以从当前请求中获取该值。
cookies[:name] = {
value: 'a yummy cookie',
domain: request.host
}下面是一些选项
domain: nil # Does not sets cookie domain. (default)
domain: :all # Allow the cookie for the top most level
# domain and subdomains.
domain: %w(.example.com .example.org) # Allow the cookie
# for concrete domain names.发布于 2015-09-02 14:36:10
只需将domain: my.subdoma.in添加到cookie中
顺便说一句:用户cookie应该在所有子域中都可用,您需要控制器检查他是否有权访问该组。这是更好的方法。
https://stackoverflow.com/questions/32345815
复制相似问题