我有這樣的從http://fromDomain.com這樣的HTML和張貼到http://toDomain.com這是一個軌道應用程序。跨域後刷新清除會話值
<html>
<h1>Test Redirect with Post</h1>
<button id="submit" onclick="send_form()">Submit</button>
<script>
function send_form() {
var form = document.createElement("form");
form.setAttribute("method", 'post');
form.setAttribute("action", 'http://todomain.com/someaction');
form.appendChild(addElement('field1', 'field1'));
form.appendChild(addElement('field2', 'field2)');
document.body.appendChild(form);
form.submit();}
function addElement(key, value){
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", value);
return hiddenField;}
</script>
</html>
在rails應用程序中,我正在做類似這樣的事情。
def someaction
if not session[:token]
session[:token] = @self.getsomehash
end
end
問題是後http://todomain.com/someaction頁面加載如果用戶點擊瀏覽器刷新那麼它將重新發布的頁面和會話哈希被重置。看起來像我當瀏覽器做轉發軌道創建一個新的會話,而不是使用現有的。
我的假設是正確的嗎?有什麼方法可以刷新並仍然堅持這些值嗎?
我對RoR託管環境並不是很熟悉,但會話cookie(臨時cookie)通常存儲在用戶代理中以在這些情況下識別訪問者。無論RoR如何進行其狀態管理,服務器端都應該採用這種機制。你使用哪種瀏覽器? – 2014-11-24 15:02:10
您是否可以使用瀏覽器的開發者模式來確定您的瀏覽器在首次訪問該網頁/網站後是否爲存儲會話Cookie?..它應該有與會話cookie關聯的域(Scope)值,如果正在創建第一個會話Cookie,是否將指定爲域? –
2014-11-24 15:05:29
我使用的是Chrome瀏覽器,如果您推薦的瀏覽器,我可以使用任何瀏覽器進行測試。我也會檢查域的範圍。 – NMK 2014-11-24 15:18:21