Sinatra不会在Chrome上重定向 [英] Sinatra not persisting session with redirect on Chrome
问题描述
作为一个例子(类似于 Sinatra文档),我正在做这样的事情:
enable:sessions
get'/ foo'do
session [:user_id] = 123
session [:session_id]#ABC,例如
重定向到('/ bar')
结束
得到'/ bar'做
#这是响应Chrome(错误)时的DEF
session [:session_id]
#当响应Chrome(错误),
时,这是零#但响应Firefox或Safari时为123(右)
会话[:user_id]
结束
我认为这与不同浏览器在重定向响应后如何处理会话有关。有没有人看过类似的东西,或者有什么想法如何解决这个问题,同时仍然使用会话?
预先感谢!
<将此添加到您的主应用文件中:
使用Rack :: Session :: Cookie,:key =>'rack.session',
:path =>'/',
:secret =>'some-random-string'
添加后,您应该能够分配会话['不管'],并按预期工作。
Sinatra is not persisting my session with a redirect on Chrome. It is creating an entirely new session and i'm losing all my previous session data.
As an example (similar to the Sinatra docs), i'm doing something like this:
enable :sessions
get '/foo' do
session[:user_id] = 123
session[:session_id] # "ABC", for example
redirect to('/bar')
end
get '/bar' do
# this is "DEF" when responding to Chrome (wrong),
# but "ABC" when responding to Firefox or Safari (right)
session[:session_id]
# this is nil when responding to Chrome (wrong),
# but 123 when responding to Firefox or Safari (right)
session[:user_id]
end
I'm thinking this has something to do with how the different browsers respond to handling the session after a redirect response. Has anyone seen something similar to this, or have any ideas on how to resolve this while still using sessions?
Thanks in advance!
Add this to your main app file: use Rack::Session::Cookie, :key => 'rack.session', :path => '/', :secret => 'some-random-string'
With that added, you should be able to assign session['whatever'] and have it work as expected.
这篇关于Sinatra不会在Chrome上重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!