ASP.NET Session State shared between IE Tabs and IE8

 

One of the common problems reported with tabbed browsing in Internet Explorer is that the session state is shared between the tabs.  Sample scenario below:-

1. User A opens an IE instance and logs into a website where a session is created.

2. User A opens another tab and tries to access the same website.  Without logging in, the user is already inside the session.

3. In this case, its clear that the session is shared between the tabs.

Problems with this behavior

User retrieves a particular record in both the IE Tabs.  On one tab, the user deletes the particular record.  Parallely on the other tab, user tries to modify the record.  There will be a data instability and would throw error.

This behavior has been complained a lot.

However, imagine if it were the other way around i.e.

Sessions not shared between the tabs

Your users signed into your site and are visiting a particular page where there are a list of links (different product links).  If your users want to compare 2 products by opening them in 2 different tabs at the same time, they would have to login again for the 2 new tabs.  That would be pretty annoying since most people open multiple windows when accessing the same site.

You have a popup in your site, where you want to quickly populate some information and get back to the original site, this wouldnt work since the popup doesnt share the session.

So there are pros and cons to this behavior and people have provided workarounds to check if there is a new instance of IE (not a great approach) or set a hidden field (somewhat okay) to check if it is the same browser etc.,

The reason for this behavior is attributed to the single process that runs the tabs and hence sharing the same session state.

ASP.NET 2.0 offered a simpler solution by way of the following config setting

<sessionState mode="InProc" cookieless="UseUri"></sessionState>

This setting basically appends the Session to the URL of the browser, so your typical URL looks like http://localhost/SampleWeb/(S(afdg3ires1ik0lmjm3pkjtzl))/default.aspx    where the highlighted portion manages the session identification.

By this way, one can open multiple tabs and still have different sessions.  The only issue with this would be the absolute URLs that are hard coded, referred to, since they change with the appending of the session URI.

In IE8 each of the tabs run under a separate process.  This would make you think that the session problem gets lost (or problem is starting :))

However, by default IE8 tabs also share the session state between them to avoid lesser sessions shared within a frame process.  Once you launch IE8, there are 2 processes started – frame process and tab process.  The frame process manages the tab processes and some of the UI rendering where the tab processes does rest of the stuff - website management.  

When an additional tab is opened, there is one more tab process added and it is also managed by the same frame process which got created initially. 

If you wish to override this behavior and get a new session, you can chose “File – New Session” .  When you do this, instead of one additional process, there are 2 processes created – a frame process and tab process and these dont share session with the original frame process.

Hence, even if you are logged in to a site and have access to session, if you chose “File – New Session” and navigate to the site, it will not share the session.

If you would like to learn more on this, visit the IE Team’s blog post at IE 8 and Reliability

Cheers !!!

posted @ Friday, April 17, 2009 6:29 PM

Print

Comments on this entry:

# Director, Microsoft .NET Development Services

Left by Will Norton at 4/17/2009 8:16 PM
Gravatar
This problem is not new and neither is the solution. But I appreciate the post. :)

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Vijay at 4/17/2009 10:48 PM
Gravatar
Very well Written Article. Actually, I am not an ASP developer, but I have faced this scenario many a times..and i loved the way..it is written.

Cheers'
Vijay
www.msigeek.com

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Sean at 4/18/2009 12:28 AM
Gravatar
The primary benefit of Tabs in a browser is simply to give users quick access to multiple browsers in a single app "window".

The expected behavior of opening another browser and visiting the same website is independent login and independent information in that browser. That should hold true for Tabbed browsing as well.

To me, sharing sessions between tabs creates more problems for the user and the developer than any benefits that can be cited for sharing the session state.

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Adrian at 4/18/2009 12:14 PM
Gravatar
I dont get this article.
My asp.net 3.5 Web application uses Forms Authentication and runs the same in IE7 and IE8 regardless of the "New Session" option mentioned in this article.

If I log-in one one IE window and open another IE window, I'm immedietaly logged into the second window the next time the second window refreshes. Then if i log-out in one window, I'm logged-out of the second window in the next refresh. I wish that it was NOT this way.

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by gunteman at 4/18/2009 4:21 PM
Gravatar
"The expected behavior of opening another browser and visiting the same website is independent login and independent information in that browser. That should hold true for Tabbed browsing as well."

I disagree. Strongly. Opening a new tab should be no different than opening a new window (ctrl-N) or a popup.

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Adrian at 4/20/2009 4:06 AM
Gravatar
I tried to do "File-New Session" but the new browser instance still uses the session information from the existing browser instance.

Session state is not stored in the URI but in session cookie. The session cookie is set to expire after a long time. The website is built with ASP.net using .Net framework 3.5.
Here is part of config file:
<sessionState timeout="525600"/>
<authentication mode="Forms">
<forms slidingExpiration="true" timeout="525600"></forms>
</authentication>
Am I doing something wrong?

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Jack at 4/20/2009 7:26 AM
Gravatar
Sad to hear that, does it mean we developer must write code base on IE version and use tab or not?

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by gunteman at 4/21/2009 1:00 AM
Gravatar
Forms authentication and session state are not related in any manner. Both use cookies (by default), but they don't share anything. Unless explicitly coded to behave differently, the session state cookie expires immediately with the browser session (hence the name "session cookie"). To make sure that forms auth cookies behave the same way, you should specify non-persistent behavior in RedirectFromLoginPage or a similar location.

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Gangs at 4/22/2009 4:14 PM
Gravatar
IE8 Storage concept<Sessionstorage,Localstorage and Databasestorage> might be useful in handling the session id from client for each IE instance & Tab. IE8 Session issues.

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Aakash at 4/23/2009 8:01 PM
Gravatar
Is it really a problem?

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by AbulMelk at 5/2/2009 5:18 PM
Gravatar
I used:
<sessionState mode="InProc" cookieless="UseUri"></sessionState>

but, still when I open a new tab it uses the same session...

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Web 2.0 Application Development at 6/15/2009 5:04 AM
Gravatar
Great post... thanks for knowledge sharing...

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by philshort at 6/22/2009 5:49 AM
Gravatar
Is it really a problem?

Yes, it is. We have users that have multiple accounts in our web app, and they log in one tab, then open another tab and log in to the app again using a different account - and repeat. They open four tabs and think they are logged in to four separate accounts. They then can't understand why all the work they do in any of the tabs gets allocated to just one of the accounts - the last one they logged in to.

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Zaphod at 7/28/2009 6:12 AM
Gravatar
"Is it really a problem?

Yes, it is. We have users that have multiple accounts in our web app, and they log in one tab, then open another tab and log in to the app again using a different account - and repeat. They open four tabs and think they are logged in to four separate accounts. They then can't understand why all the work they do in any of the tabs gets allocated to just one of the accounts - the last one they logged in to."

Is that not simply a bad design of the application?

Why would the user be shown a login screen when they are already logged in? Surely the app should redirect to the post login page? That would eliminate confusion of which login is being used - you would clearly see that you need to log out of one account to log into another.

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Mukadeen at 7/30/2009 1:05 AM
Gravatar
I hate this session sharing ... its causing a lot of problems to our site!!!

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by Ole at 8/12/2009 3:42 AM
Gravatar
"Is it really a problem?"

Yes it is. Imagine you have a application with sensitive information. A user opens the app, loggs in. He or She opens another window doing some work or fetching flight dates for his or her next trip. Then he closes the asp.net app window but leaves the flight-ticket-window open.

Then he or she goes to the toilet.

Another colleague enters the room, takes seat and opens another window pointing to the asp.net URL and Whoppa ... is signed in automagically ... using the old session.

But this is not a IE only problem. All current browsers behave the same way. So you would have to implement a security mechanism yourself by hooking into the window close event. Or override the standard session timeout behaviour refreshing every second or two implementing a custom timer. But the problem of multiple parallel sessions remains.

So, the feature of IE 8 to open a new session is a bless. And it works.

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by VB Guest at 9/19/2009 12:01 AM
Gravatar
"Sessions not shared between the tabs"
i thought any window/popup opened from current browser will share the same session. in this case the new tab also will share the existing session.

Even though new tabs when not opened from the parent window does not share the session. it will share when opened from the current tab using window.open.

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by software development london at 10/12/2009 9:55 PM
Gravatar
Quite inspiring,

thanks for this explanation, you have answered my Internete8 tab realted questions

Thanks

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by PRITI at 10/28/2009 11:33 PM
Gravatar
NICE POST
THANKS A LOT... IT SOLVED MY PROBLEM :)

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by rudedevil09 at 11/4/2009 5:03 PM
Gravatar
Does anyone have a concrete solution to this problem of session sharing????

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by PS at 11/23/2009 12:03 AM
Gravatar
I am also having same issue. I have used <sessionState mode="InProc" cookieless="UseUri"></sessionState>
My URL is http://XXX/AAA/home.aspx.
But first time i need to click twice to get
http://XXX/AAA/(S(y5oapzqkb5m3p12blyzrrg55))/home.aspx
Can you pls let me know How to solve this issue ?

# re: ASP.NET Session State shared between IE Tabs and IE8

Left by PS at 11/23/2009 12:36 AM
Gravatar
How to solve the same issue hidden variable. Can you pls give sample or steps... It looks ugly to add / have session id in Url.

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345