问题
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