Rails 3.2 session_id永远不会改变

时间:2012-05-15 22:29:03

标签: ruby-on-rails session

我在我的Rails应用程序上运行了一个骨干应用程序,它正在发出许多AJAX请求。奇怪的是,我的浏览器存储的会话ID cookie似乎永远不会改变。我可以看到下一个请求正在进行,并且回复成功。但是,响应仍然依赖于旧的会话ID,因此我无法以任何方式注销或更改用户状态。

以下是发送标头的示例:

请求/login.json:

Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:_session_id=BAh7CEkiD3Nlc3Npb25faWQGOgZFRkkiJWY0YTI1Y2I5ZDE5MTgyYjJmN2MzMzZiMmE5ZWE2ZTAyBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTB1ZEozbzJCbUl4ZjluUDdCZVVEOXBhL0ZUeXNVRnFiMlFLblFTVUZPNGM9BjsARkkiDHVzZXJfaWQGOwBGaQg%3D--cf57849d4a4c0cbc5608574d959a772080b3afc5
Host:localhost:3000
If-None-Match:"7363e85fe9edee6f053a4b319588c086"
Referer:http://localhost:3000/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5
X-CSRF-Token:0udJ3o2BmIxf9nP7BeUD9pa/FTysUFqb2QKnQSUFO4c=
X-Requested-With:XMLHttpRequest

来自/login.json的回复:

Cache-Control:max-age=0, private, must-revalidate
Date:Tue, 15 May 2012 22:44:46 GMT
Etag:"7363e85fe9edee6f053a4b319588c086"
Server:WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
Set-Cookie:_session_id=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWY0YTI1Y2I5ZDE5MTgyYjJmN2MzMzZiMmE5ZWE2ZTAyBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTB1ZEozbzJCbUl4ZjluUDdCZVVEOXBhL0ZUeXNVRnFiMlFLblFTVUZPNGM9BjsARg%3D%3D--b16d1f8e4bba3c86d5e3e9ece1ae50f1ad898d00; path=/; HttpOnly
X-Request-Id:8e278bdd3504257bcb9956e068ca3ca3
X-Runtime:0.014739
X-Ua-Compatible:IE=Edge

注意它给了我一个新的会话ID。然而,当我提出下一个请求时......

Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:_session_id=BAh7CEkiD3Nlc3Npb25faWQGOgZFRkkiJWY0YTI1Y2I5ZDE5MTgyYjJmN2MzMzZiMmE5ZWE2ZTAyBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTB1ZEozbzJCbUl4ZjluUDdCZVVEOXBhL0ZUeXNVRnFiMlFLblFTVUZPNGM9BjsARkkiDHVzZXJfaWQGOwBGaQg%3D--cf57849d4a4c0cbc5608574d959a772080b3afc5
Host:localhost:3000
If-None-Match:"53135bfd970c6b34f39ea3c4780ed240"
Referer:http://localhost:3000/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5
X-CSRF-Token:0udJ3o2BmIxf9nP7BeUD9pa/FTysUFqb2QKnQSUFO4c=
X-Requested-With:XMLHttpRequest

Cookie从未改变过。

1 个答案:

答案 0 :(得分:0)

我明白了。我有一个异步。请求同时触发,因此浏览器永远无法获得正确的会话ID。