Search code examples
c#asp.netwebformshttpcontext

Is there a scenario where Context.Items would cease to exist?


I'm using Asp.Net web forms to create a website and using Context.Items to share a small amount of expensive data around the page parts.

I'm aware of some of the pitfalls of using Session, but given Context.Items is only live for the duration of the request, is there any scenario where it could be disposed or not found, aside from massive performance problems?

It seems highly unlikely but I've not been able to find any confirmatory info, so would appreciate any advice.


Solution

  • Context is available for the duration of the request on the thread controlled by ASP.NET. You could run into issues trying to access it across threads or in background threads, or after the request completes. Otherwise, what you're describing sounds like the exact use case for Items.

    Maybe this article (although dated) helps confirm your assumptions: A Matter of Context