Session variables in Google Chrome persist after browser closes

泄露秘密 提交于 2019-12-24 13:17:44

问题


I'm using session variable to store some data. I want the data to be lost when the browser closes, or session times out. Everything works in IE and FF, but chrome persists session variables after browser has been closed.

var myName = Session["Name"];

if (myName == null) {
  myName = "defaultName";

}

It will not fall into the if block if i close and re-open chrome, as the session variable is persisted. Is there a way to ensure session variables are lost after google's chrome is closed ?


回答1:


Remember HTTP is a stateless protocol, so you cannot determine if an user has closed the browser or with browser window open. This is the reason we use sessions timeout - you can reduce the timeout in order to close inactive sessions, but this may lead to other users to have their session timed out.

Closing browser doesn't mean the Session is destroyed. But would be destroyed after some idle time.

Read this : Session Handling for some work around methods on how to handle session timeouts better



来源:https://stackoverflow.com/questions/24429246/session-variables-in-google-chrome-persist-after-browser-closes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!