I would like to store some objects only for one request through the session state. I can't seem to think of an easy way to accomplish this. This is exactly what ASP.NET MVC's TempData object does. Could anyone provide me with a link or some examples of how to have an object in session state only survive one additional request?
I was thinking, this could be possibly accomplished by making a custom dictionary object, which stores an age (# of requests) on each item. By subscribing to the Application_BeginRequest and Application_EndRequest methods, you could perform the required cleanup of the objects. This could even probably facilitate making an object that stored a piece of data for X requests, not just one. Is this on the right track?
I implemented something very similar to what you describe in the Application_AcquireRequestState method of Global.ascx.cs. All my session objects are wrapped in a class that keeps count of the number of reads.
You can find something very similar here : http://maff.ailoo.net/2009/06/build-a-flashmessenger-system-in-aspnet-mvc/