How can I tell if 2 browser windows are sharing their session?
Many of our users, internal and external, start our web application. Then at some later point, they open a new window from within the browser. They want to have 2 independent sessions of the application running. However, by doing it this way they are actually using the same session data.
Is there a way, in code, to determine if there is another browser window open with the same session?
We're using VS 2008, C# and/or VB.Net.
Thanks.
COMBINING MY RESPONSES FROM BELOW:
Maybe I'm saying this wr开发者_StackOverflow中文版ong. When they open a second window and change it to a different widget number, and then go back to the original window, on the next post-back it will be using the second window's widget number, not its own
We are using IE7.
The major browsers that I've tested apps on (IE, FF and Google Chrome) all default to using the same collection of cookies regardless of whether you are opening a duplicate web page in a new tab or a new browser instance.
The result is that 2 different tabs, or 2 instances of the same browser, by default, will look like the same session to the server.
Because the multiple instances use the same cookies, the server cannot tell requests from them apart, and will associate them with the same Session data, because they all have the same SessionID, assuming cookie-based SessionID.
Generally there is nothing wrong with this behaviour, and you would have to have a good business case against that behaviour to want to code a work around.
I do not believe it is possible to distinguish the different browser tabs from server side code. There may be some sort of client side script hack that would help.
Would it help to include a Html meta refresh tag so that the various tabs at least update themselves periodically?
If, on the other hand, what you are after is to treat a group of user/server interactions as a kind of "session within a session", you may be able to do this by storing a random Guid (or Widget Number) in ViewState, and checking it on postback.
Hope this helps.
- IE8 - shares session between tabs and browser instances; new session can be started using File->New Session command
- IE7 - shares session between tabs but not between browser instances
- Firefox - shares session between tabs and instances; another Firefox can be started in different profile (firefox.exe -P "profileName" -no-remote) and then have separate session
See http://blogs.msdn.com/ie/archive/2009/05/06/session-cookies-sessionstorage-and-ie8.aspx for discussion of this topic for IE7 and IE8.
They're not sharing the same data. A new session is started in the new browser window and a separate trip to the database is initiated.
You can inspect the headers in Fiddler or you can output the Session.ID in the Windows. Sessions are created for each browser instance, not each window.
精彩评论