Search code examples
c#asp.netcustom-controlsthread-local-storageuicontrolstate

Is there something like RequestLocal (like ThreadLocal)?


In C# there is a class ThreadLocal. You can use it to define a static field that only exist within the scope of a thread.

I am looking for something similar for use in an ASP Custom Control. I need to define a static field that is shared between all instances of this control, within the scope of a request.

Does there exist something out of the box for it?


Solution

  • You can use the HttpContext.Items dictionary that is associated with each request.

    In ASCX code, for example:

    this.Context.Items.Add("key", value);
    

    See Documentation