3

So in a server code of a silverlight app I see multiple references to System.Web.HttpContext.Current.User.Identity.Name. The question is: if System.Web.HttpContext.Current is a static property then how is it that different simultaneous requests are processed using different System.Web.HttpContext.Current objects?

I guess I'm missing something simple here.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
ren
  • 3,843
  • 9
  • 50
  • 95

2 Answers2

4

Each request is serviced by a thread. Put another way, a thread can service only one request at a time.

Now HttpContext.Current is backed by CallContext.HostContext, which is effectively a thread-static property (the property getter / setter works on a per-thread basis).

Gets or sets the host context associated with the current thread.

And that's how HttpContext.Current manages to always return the correct context for each request, even when multiple requests are being serviced in parallel - the current thread is associated with a HttpContext, which in turn is associated with a specific request.

Ani
  • 111,048
  • 26
  • 262
  • 307
0

It is static but on the current Request.

"Gets or sets the HttpContext object for the current HTTP request."

see: msdn- HttpContext.Current Property

John Sobolewski
  • 4,512
  • 1
  • 20
  • 26