Solved

asp.net vb.net session issue with multiple browser tabs

Posted on 2013-05-29
4
1,517 Views
Last Modified: 2013-06-02
I am stepping in to the middle of a very big asp.net/vb.net app project.

The app uses asp.net membership forms authentication to manage users and logins.

The app also uses sessions variables quite a bit to pass data around (no data is passed around in the query string).

The issue is that a user will pull up a record which sets a session variable for the recordid.
Then they will need to jump to another record, but keep the current record open.
So they will open a new browser tab and look up the other record which then changes the session variable.
Then they will go back to the first record and add a child record.  But it gets added to the wrong parent record because of the session variable switch.

I have done a whole bunch of google'ing and reading on this, but I can't find an easy fix.
(Yes, I no there may not be an easy fix).

One option would be to prevent them from opening the site in a 2nd tab.
Or at least make sure that it starts a new session if they open in 2nd tab.
I have looked in to this, but haven't found a solution.

Any suggestions would be much appreciated.

Thanks!
0
Comment
Question by:kevinvw1
  • 2
4 Comments
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 39206700
In all other questions here where session id's are stored in cookies, they have discovered that the 'cookie jar' is common to all open windows of a browser.  If you change the value in one window, it changes in ALL windows.  There is no known fix for this problem.  All browsers act this way.  

However... each browser keeps it's Own cookies and does not share them with the other browsers.  So you can open a different browser and not change the session in the first browser.
0
 
LVL 16

Accepted Solution

by:
Stephan earned 250 total points
ID: 39206710
Like davebaldwin said: a session is persistend in all windows of thesame browser.

The only approach to fix this, is using URL's. If you do webforms you can try viewstate and in mvc try viewdata.
0
 

Author Comment

by:kevinvw1
ID: 39215372
Actually it looks like DOM sessionStorage may help me in this situation.

sessionStorage variables appear to be unique within sessions and within tabs.

Something like this -

if (""+sessionStorage.getItem("id") == "null")
      {      
            var milliseconds = new Date().getTime();
            alert ("Now setting to - " + milliseconds);            
            sessionStorage.setItem("id",milliseconds);
      }
}

I just ran a test and even using "Duplicate Tab" gives me a new local id value.

So between cookies and DOM sessionStorage I think I can prevent the user from opening 2nd session (in same browser).

Thanks for your help.
0
 
LVL 16

Expert Comment

by:Stephan
ID: 39215393
Hi Kevin,

Keep in mind that sessionStorage is not available in all browsers (doesn't work in IE7)
Here is a list of browsers that support and doesn't support sessionStorage:
http://caniuse.com/namevalue-storage

Check out the following polyfill:
https://gist.github.com/tagawa/2880273
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now