6

Im sure there was a request-wide object-based storage medium, similar to HttpContext.Current.Session, that persisted globally just for the life of a single request, but I cannot for the life of me remember it.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
maxp
  • 24,209
  • 39
  • 123
  • 201
  • Do you mean [ViewState](http://msdn.microsoft.com/en-us/library/ms972976.aspx)? It's not request wide since it stores values across postbacks. Perhaps `Request.QueryString` or `Request.Params`, but this is also to maintain values across postbacks(and detecting user submit params)? Hmm, if you need to store values only for a single Request, why don't you simply use a class member of your page? It's lifetyme is exactly the lifetime of the Page. – Tim Schmelter Oct 27 '11 at 09:45
  • @TimSchmelter, It was HttpContext.Items - its useful because it can be accessed from a static context – maxp Oct 27 '11 at 09:50

3 Answers3

12

I bet you're thinking of HttpContext.Items.

Gets a key/value collection that can be used to organize and share data between an IHttpModule interface and an IHttpHandler interface during an HTTP request.

Very useful for sharing state between HttpModules, HttpHandlers and pages from different parts of the request cycle.

More reading:

Note that HttpContext.Items works for both ASP.NET WebForms and ASP.NET MVC but it there's a caveat when using both in the same web app. More about that in this question.

Community
  • 1
  • 1
Markus Olsson
  • 22,402
  • 9
  • 55
  • 62
0

There's TempData in ASP.Net MVC. Items persisted there survive only from one request to the next. Ultimately, its storage is session state.

Steve Rowbotham
  • 2,868
  • 17
  • 18
0

Couldn't you use ViewData (if its ASP.NET MVC) or ViewState (if its ASP.NET)?

Echilon
  • 10,064
  • 33
  • 131
  • 217
Yannis
  • 6,047
  • 5
  • 43
  • 62