Sessions do not work in Internet Explorer in Rails

Recently I had a strange problem when sessions didn’t work on my site on Rails in production environment. The problem was in Internet Explorer while it worked in Firefox and Chrome.

I found out that Internet Explorer doesn’t set cookies for some reason.

I’ve tried many settings for session_store in my config like

config.session_store :cookie_store, key: '_sess', :domain => :all
 
config.session_store :cookie_store, key: '_sess', :domain => '.mysite.com'
 
config.session_store :cookie_store, key: '_sess', :domain => '.mysite.com', :secure => false

and many many others. But it didn’t help.

The problem was in the name of my subdomain – it had an underscore ( “_” ), for example, dev_rails.mysite.com.

IE has problems accepting cookies from subdomains that contain underscore.

In order to work in IE subdomains must meet the requirements of the URI RFC.

 

Read more:

http://stackoverflow.com/questions/794243/internet-explorer-ignores-cookies-on-some-domains-cannot-read-or-set-cookies