开发者

Rails, Subdomain based cookies

开发者 https://www.devze.com 2023-03-08 01:08 出处:网络
I have a rails application which is Subdomain based. It also contains REST API which can be publicly accessed to our clients. I have an another client application through which I am accessing the REST

I have a rails application which is Subdomain based. It also contains REST API which can be publicly accessed to our clients. I have an another client application through which I am accessing the REST API of the main app.

When I am accessing both the apps on the same browser and logged in the main app, I am not able to access the REST API of different Subdomain in client app as cookie get stored according to the domain accessed.

开发者_StackOverflow中文版

Is there any way to differentiate the cookies based on Subdomain.

Thanks in advance.


You should set cookie's domain as .yourdomain.com so that your cookies are set for main domain and for all subdomains.

Rails 3 on config/initializers/session_store.rb:

Rails.application.config.session_store :cookie_store, :key => '_my_key', :domain => ".yourdomain.com"

Rails 2.3+ on config/environment.rb:

config.action_controller.session = { :key => '_my_key', :domain => '.yourdomain.com' }
0

精彩评论

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