在System.Web.HttpContext.Current混乱 [英] confusion over System.Web.HttpContext.Current
问题描述
因此,在Silverlight应用程序的服务器code我看到 System.Web.HttpContext.Current.User.Identity.Name
多次引用。现在的问题是:如果 System.Web.HttpContext.Current
是一个静态属性,则它是如何不同的并发请求使用不同的处理的System.Web .HttpContext.Current
对象?
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.
推荐答案
每个请求是由一个线程服务。换句话说,一个线程可以服务在同一时间只有一个请求。
Each request is serviced by a thread. Put another way, a thread can service only one request at a time.
现在 HttpContext.Current
由<一个支持href=\"http://msdn.microsoft.com/en-us/library/system.runtime.remoting.messaging.callcontext.hostcontext%28v=vs.100%29.aspx\"相对=nofollow> CallContext.HostContext
,这是的有效的线程静态属性(属性getter / setter方法适用于以每个的线程的基础上)。
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.
这是如何 HttpContext.Current
管理总是返回正确的上下文为每个请求,即使多个请求被并行服务 - 当前线程与相关联HttpContext的,这又与一个特定请求相关联
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.
这篇关于在System.Web.HttpContext.Current混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!