In ASP.NET MVC 2, the write lifetime in TempDataDictionary was just one HTTP request.
This translates to setting the value to one request, redirecting and accessing the same element at the other end of the line. After that, the entry will be unavailable, regardless of whether you read the value from the dictionary at the last end of the line or not.
Since ASP.NET MVC 3 (I believe), this implementation detail has changed significantly.
Entries in TempDataDictionary now deleted only after they are read.
MVC 4
public object this[string key] { get { object obj; if (!this.TryGetValue(key, out obj)) return (object) null; this._initialKeys.Remove(key); return obj; } }
and
public bool TryGetValue(string key, out object value) { this._initialKeys.Remove(key); return this._data.TryGetValue(key, out value); }
MVC 2:
public object this[string key] { get { object value; if (TryGetValue(key, out value)) { return value; } return null; }
and
public bool TryGetValue(string key, out object value) { return _data.TryGetValue(key, out value); }
Since most people seem to put the items in the TempData collection in one request and immediately read them back in the next next request, the functionality seems to be the same draft.
In scenarios where this is not the case, for example, if you want to read a TempData record, if it is redirected to one place, and expecting it to be deleted when requesting other resources and navigating backwards, this change has a big impact.
There is no longer an entry available for one HTTP request, but available for many HTTP requests, be it available for only one dictionary.
I would like to know more about this change in implementation, what were the reasons for this change, was it just to serve multiple redirects, or are there deeper benefits?
In addition to this, I am intrigued to find out if there is anything inline that now serves a single HTTP request for data sharing in the same way that TempData used for maintenance?