多个用户可以共享一个 HttpApplication 实例吗?
我使用本文顶部的表格作为参考。我有三个问题:
1 - 多个用户(来自不同的物理位置)可以共享一个 HttpApplication 实例吗?如果是这样,这是默认发生的吗?
2 - 多个用户(来自不同的物理位置)可以共享一个 HttpApplicationState 实例吗?如果是这样,这是默认发生的吗?
3 - ASP.NET 应用程序的多个用户是否可以共享单例实例或静态变量值?如果是这样,这是默认发生的吗?
感谢您解决这个问题。
I've used the table at the top of this article as a reference. I have three questions:
1 - Can multiple users (from different physical locations) ever share an HttpApplication
instance? If so, does this happen by default?
2 - Can multiple users (from different physical locations) ever share an HttpApplicationState
instance? If so, does this happen by default?
3 - Can multiple users of an ASP.NET application ever share a singleton instance or a static variable value? If so, does this happen by default?
Thanks for clearing this up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的所有六个问题的答案都是肯定的。
每个用户的状态应该存储在会话中。
The answer to all six of your question is yes.
Per-user state should be stored in the Session.
HttpApplication 包含每个 w3svc.exe 实例上的 Asp.Net 应用程序的状态。因此,应用程序中的每个 Web 服务器都会存储应用程序状态。如果您使用网络园艺,则 HttpApplication 对象还有其他问题。
同一服务器上同一线程上的所有用户将共享 HttpApplication、HttpApplicationState 和所有静态变量值。当多个 HttpApplication 实例在服务器上运行时,并发用户将不会访问这些对象的同一实例。我不建议在这些对象中存储值...使用 Cache 对象来存储您希望在服务器上的用户之间共享的值是更好的做法。
缓存对象
缓存对象可以采用依赖项和过期时间值...这将允许您控制存储在服务器上的值的“新鲜度”。
每个用户的值应存储在 Session 对象中。
会话对象
The HttpApplication contains the state of the Asp.Net application on a per w3svc.exe instance. So, per web server in your application, the application state is stored. If you are using web gardening, there are other concerns with the HttpApplication object.
All users on the same server, on the same thread will share HttpApplication, HttpApplicationState, and all static variable values. When multiple HttpApplication instances are running on a server, concurrent users will not be accessing the same instance of these objects. I do NOT recommend storing values in these objects... it is a much better practice to use the Cache object to store values you wish to share across users on a server.
Cache Object
The Cache object can take dependencies and expiration time values... this will allow you to control the 'freshness' of the values you are storing on a server.
Per user values should be stored in the Session object.
Session Object