开发者

Why am I losing session when working with a dashed domain name (example-dashed.com)?

I have a website which is www.abrisud.com. This website has 7 domain names (one for each language): abrisud.com, abrisud.it, abrisud.de, etc... and abrisud-enclosure.co.uk.

The problem is on the last one: I am losing my session on every single request. Each Time I load a page I have a different session ID. On the other domains everything is working just fine.

The website is running r开发者_如何学Cuby 1.8.7 and rails 3.0.0.

I am really convinced that the problem comes from the "-" in the domain name but I just can't find anything (or almost anything) on the subject through the web.

Hopefully I am being clear enough, if not just tell me.


Here is the answer :

From Module ActionDispatch::Http::URL (Rails 3.0.x), be sure to read the comments ;-)

# Returns the \domain part of a \host, such as "rubyonrails.org" in "www.rubyonrails.org". 
# You can specify a different <tt>tld_length</tt>, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk".
def domain(tld_length = 1)
  return nil unless named_host?(host)

  host.split('.').last(1 + tld_length).join('.')
end


Well, calling the domain method with the appropriate _tld_lenght_ argument did not play the trick, the request.domain (abrisud-enclosure.co.uk) was good, but not the session_domain (still co.uk).

So I had to add the following lines as a before filter to my application_controller :

def set_session_domain
  request.session_options[:domain] = request.domain
end

If you have a better solution I am open to it as I think this is a really dirty fix.

Thanks


I have taken a peak at your site, the cookie is set with: domain=co.uk;path=/

So the problem is within your rails stack and not the browser(s) - time to do some debugging :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜