HttpContext 在 .NET 中如何工作
我想了解 httpcontext 在 .NET 中如何工作的细节?
我无法理解的是 HttpContext 类有一个静态 HttpContext 对象的字段。那么对于来自客户端的每个请求是否都会创建一个 httpcontext 实例?为什么它定义为静态?这是否意味着一个应用程序只能有一个 httpcontext ?
我很困惑,所以提问的方式可能有点复杂。我希望这是可以理解的。
提前致谢,
I am trying to understand the detail of how httpcontext works in .NET ?
What I couldnt understand is the class of HttpContext has a field of static HttpContext object. So for each request from client creates an instance of an httpcontext or not ? Why it defined as static ? Does it mean one application can only has one httpcontext ?
I am confused so the way that ask the question can be little bit complex. I hope it is understandable.
Thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您访问静态成员时,它会解析与线程相关的当前请求。
不,这并不意味着只有一个线程,就像 Thread.Current 并不意味着只有一个线程一样。每个请求都有不同的 HttpContext。
作为做类似事情的一种简单方法(但我不知道它是否是这样实现的);
When you access the static member, it resolves the current request relative to the thread.
No, this does not mean there is only one, in the same way that Thread.Current doesnt mean there is only one thread. Each request has a different HttpContext.
As a trivial way to do something similar (I don't know if it is implemented this way, though);