更新了问题,使其更加清晰
我知道你可以设置session_store的域来共享子域之间的会话,如下所示: Rails.application.config.session_store :cookie_store, :key => '_my_key', :domain => "mydomain.com"
在Rails 3中,设置有:domain => :all什么作用?它不能让您在顶级域名之间共享会话,Cookie无法做到这一点.文档说它假设一个顶级域名.那么如果多个域访问您的应用会发生什么?
在我的应用中,我的用户可以创建一个主域的个人子域,但也可以通过他们自己的自定义域访问该子域.
什么是正确的session_store域设置,这样我可以:a)在我的主域名,如"mydomain.com" B)谁访问他们的个人子域名,例如"user1.mydomain.com"用户的所有域共享会话通过CNAME定制像"some.otherdomain.com"这样的网址仍然可以创建单独的会话.
谢谢
我有一个应用程序,用户可以登录到他们的公司子域.
我用设计.此代码将用户从根域重定向到子域.
def after_sign_in_path_for(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
subdomain_name = current_user.firm.subdomain
if current_subdomain.nil?
# logout of root domain and login by token to subdomain
token = Devise.friendly_token
current_user.loginable_token = token
current_user.save
sign_out(current_user)
flash[:notice] = nil
home_path = valid_user_url(token, :subdomain => subdomain_name)
return home_path
else
if subdomain_name != current_subdomain.name
# user not part of current_subdomain
sign_out(current_user)
flash[:notice] = nil
flash[:alert] = "Sorry, invalid user or password for subdomain"
end
end
super
end
Run Code Online (Sandbox Code Playgroud)
它在chrome,firefox,opera和safari中运行得非常好,但它在IE9中不起作用.我没有收到任何错误消息.从日志中我看到用户获得了sigend,当用户被重定向到主页时,他/她是未经授权的.有没有人知道发生了什么?形成日志.
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"?",
"authenticity_token"=>"JaffZi9f+Uyovuya8wR2u7LjG9w/3wdUDqTqONt/kFM=",
"user"=>{"email …Run Code Online (Sandbox Code Playgroud) 我的应用程序的注册和登录过程发生在安全的子域中.出于这个原因,我修改config/initializers/session_store.rb了一下
if Rails.env.production?
AppName::Application.config.session_store :cookie_store, :key => '_app_name_session', :domain => '.app_name.com'
else
AppName::Application.config.session_store :cookie_store, :key => '_app_name_session'
end
Run Code Online (Sandbox Code Playgroud)
这样就可以跨子域共享会话.
如何在子域之间共享永久性cookie,以便当我在一个子域上设置永久性cookie时cookies.permanent[:some_key] = 'some value',我可以通过另一个子域访问该cookie cookies[:some_key]?