问题
I'm hoping someone can clarify this behavior for me, and explain how ASP.NET is deciding when to treat something like a new Session.
A) In Internet Explorer I load the ASP.NET site in question. It starts a new Session.
B) If I go to menu File - New Window... it stays within the same Session.
C) If I launch a new instance of Internet Explorer and load the same page it starts a new Session.
I'm confused by step C. I'm expecting it to be the same session based on my remote IP.
What is IIS / ASP.NET doing to decide that this is a new session?
Is it looking at my remote port that the new instance of IE is using? When you kick up a new window with File - New it uses the same remote port as the parent.
回答1:
Sessions in IIS/ASP.NET are based on cookies with a session scope, meaning that they get destroyed when the browser is closed, and apparently they are not shared within different processes of Internet Explorer.
When you open a new browser window with File > New Window the window will be handled by the same process as the first (i.e. the same iexplorer.exe). When you lauch IE from the start menu you get a new process, and you will now have two iexplorer.exe in the Task Manager. I think that it's only IE 7 that will spawn multiple processes.
As a side note, IE 8 will have have a single process per tab / window, like Google Chrome has. I don't know if these browsers share session cookies amongs the processes, but it's certainly something to keep in mind when testing using one of these browsers.
回答2:
By default, ASP.NET tracks sessions through cookies. A new IE instance does not have the session cookie, resulting in a new session. However, using File -> New Window from an existing IE window will create a new window with the same cookies as the "parent", allowing ASP.NET to use the existing session.
回答3:
I'd wonder if the new IE instance would have the same cookies that happen in case B, where while it is a new window it is using the same process. It is usually in the cookie or in the querystring that there is a value used to map sessions to various clients.
回答4:
It would appear the session data is getting cached per process. A) and B) exist in the same process, whereas launching a new instance of IE will be creating a new process.
来源:https://stackoverflow.com/questions/303859/asp-net-and-sessions-new-browser-instance-versus-new-browser-window