Search code examples
c#asp.netdata-persistence

Storage medium for the lifecycle of a single request?


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.


Solution

  • 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.