Losing session in rails 2.3.2 app using subdomain

前端 未结 10 1007
轻奢々
轻奢々 2020-12-06 13:39

I have a 2.2.3 app which I upgraded to 2.3.2

It\'s a multi-site (using subdomain) that creates one top level session for all sites.

This is how I change the

相关标签:
10条回答
  • 2020-12-06 14:17

    A more bullet proof solution would be to check if the session already exists or not. If you are blindly replacing the whole session object it may trip you up in the future.

    if ActionController::Base.session
      ActionController::Base.session[:domain] = '.example.com'
    else
      ActionController::Base.session = { :domain => '.example.com' }
    end
    

    I like to do this in an initializer file.

    0 讨论(0)
  • 2020-12-06 14:19

    we had the same problem (losing sessions, without subdomain), with nginx + thin. Migrating to apache + passenger (last version) fixed the problem.

    0 讨论(0)
  • 2020-12-06 14:19

    It could be added in the same place where you set the session key and secret

    config.action_controller.session = {
          :key => '_app_session',
          :domain => '.domain.com',
          :secret => 'secret'
    }
    
    0 讨论(0)
  • 2020-12-06 14:20

    In Rails 2.3 you should use

    config.action_controller.session[:domain] = '.example.com'
    
    0 讨论(0)
  • 2020-12-06 14:20

    You must indicate:

    .example.com
    

    (notice the leading dot) in order for the session cookie to apply to example.com as well as its sub-domains.

    0 讨论(0)
  • 2020-12-06 14:22

    I had the same problem with cookie-based sessions. Upgrading to Passenger 2.1.3 seemed to fix the issue.

    0 讨论(0)
提交回复
热议问题