Last post Nov 30, 2015 03:29 PM by Rion Williams
Nov 30, 2015 12:38 PM|RBuxton|LINK
I went from the second tab to the third it no longer existed. It's a bool, so in the first tab I set it to true and when I come into the second tab it was still true, but when I went from the second tab into the third tab surprisingly it was false.
Is there another way to maintain state across tabs in a browser session? Am I doing something wrong?
Here's the definition of my variable:
protected bool acceptedTerms
// Initialize if not already
if (Session["acceptedTerms"] == null)
Session["acceptedTerms"] = false;
Session["acceptedTerms"] = value;
Within the code I only set it to true in one place otherwise it should be picking up the value from the session. other than the first time in.
Nov 30, 2015 02:17 PM|Rion Williams|LINK
Session is handled at the application level (and not the client) on a per-user basis, so if you store it within a single tab and open up another one, you should be able to access it within N number of tabs that you open after that. The only reason that I
can think that it wouldn't work would be if something was explicitly clearing out your Session.
You are setting these values prior to opening other tabs correct?
Nov 30, 2015 02:50 PM|RBuxton|LINK
After some more testing this morning I sort of realized my problem and I'm still not sure I understand the behavior I'm seeing. I think of our application as a single website because it all run under a single "umbrella" site, but in reality it is made up
of 4 different applications. When I said I was opening a new tab, it was actually one of the other applications. What I find so strange is that the first application actually did get my session variable. I can't figure that out, but I tested this several times
and it was getting it.
I am still trying to figure out a way to pass a value between the applications without having to use a cookie or some other physical means.
Nov 30, 2015 03:29 PM|Rion Williams|LINK
Cookies are generally great for this type of behavior (most sites use them all the time to enable associations or to pass data along between one or more sites). Another option would be to use URL QueryString parameters, but in my opinion that can get rather
nasty and cumbersome. Out of those two options, cookies are going to be my recommendation.
It's possible to actually share a single Session across multiple applications similar to the approach discussed in
this related thread (or simply search for "Sharing Session across multiple ASP.NET Applications" in your favorite browser), which could be an option for you as well.