Reputation: 473
First off, this is my own project, not a homework assignment.
Here's the situation. I have a web application (ASP.NET w/ MVC 5) and I use the session to store certain things (e.g. user info). Now, there are two tabs open, each on one part of the page. We will call them Tab A and Tab B. Here's the scenario:
Tab A is open to Page A
Tab B is open to Page B
In Tab B, the user does an action which requires the update of a session variable. Thus, I write the new data to the session variable via an Ajax call to a controller method.
If I refresh Tab A, however, the data in the session variable does not update for Tab A.
If I then refresh Tab B, then go back to Tab A and refresh, then the data in the session updates for Tab A.
The other odd thing is, if I refresh Tab A, but never refresh Tab B, then Tab B thinks the session data never updated either.
I'm not sure why the session data won't update until I refresh Tab B.
Upvotes: 0
Views: 242
Reputation: 4101
I've seen this before - it wasn't the session variable when it happened to me, it was the browser cache. I had to set the page not to cache using a combination of server-side and client-side methods.
Client side I found I needed to do this to force all my supported browsers not to cache:
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
Server-side I had to do this:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.AppendCacheExtension("no-store, must-revalidate");
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Expires", "0");
A little brute force, I'll admit, but this was the only way I could make everything not cache in my environment.
Upvotes: 1