ASP.NET:会话对象是我可接受的静态变量解决方案吗?
我已经阅读了有关此主题的多个主题,并且需要对我在书中读到的几句话进行一些澄清:
如果您在进程中存储会话状态,则您的应用程序不可可扩展。其原因是 Session 对象存储在一台特定服务器上。因此在进程中存储会话状态不适用于网络场。
- 第一句中的“可扩展”是什么意思?
- 第三句是否意味着如果我的应用程序驻留在共享网络主机上,我不应该使用 Session["myData"] 来存储我的内容?如果是这样,我应该使用什么?
谢谢。
I've read several threads about this topic and need some clarification on a few sentences I read in a book:
If you store your Session state in-process, your application is not scalable. The reason for this is that the Session object is stored on one particular server. Therefore storing Session state in-process will not work with a web farm.
- What does "scalable" in the first sentence mean?
- Does the third sentence means if my app resides on a shared web host, I shouldn't use Session["myData"] to store my stuff? If so, what should I use?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1:
这种意义上的可扩展性:
2:
使用会话服务器或在 SQL Server 中存储会话,如下所述< a href="http://msdn.microsoft.com/en-us/library/ms178586.aspx" rel="nofollow">此处。
1:
Scalability in this sense:
2:
Use a session server or store sessions in SQL Server, which are described here.
ASP.NET 可以将应用程序的所有组合会话信息(“会话状态”)存储在服务器端的 3 个可能位置(客户端 cookie 也是可能的,但这是一个不同的情况):
1) In-process 不可扩展的原因是,如果您的需求超出了单个 IIS 服务器的容量,则多个服务器无法使用 In-process 会话状态。如果您确定共享托管方案能够满足您的需求,则无需担心。
2) 当您在
Session["Name"]
中存储某些内容时,ASP.net 会将该数据存储在应用程序配置为存储会话状态的任何位置。如果您想更改会话状态的存储位置,您所需要做的就是配置 web.config 文件。如果您使用共享托管环境,则您的 IIS 部署将被视为单个服务器,即使实际服务器无疑位于某种场中。请参阅:MSDN 会话状态模式
ASP.NET can store all the combined Session information for an Application (the "Session State") in 3 possible places on the server-side (client cookies is also possible but that is a different story):
1) The reason In-process is not scalable is if your needs exceed the capacity of a single IIS server, multiple servers can't use an In-process session state. If you have determined a shared hosting scenario will fulfill you needs, you don't need to worry about it.
2) When you store something in
Session["Name"]
, ASP.net stores that data wherever the application is configured to store Session state. If you want to change where Session state is stored, all you need to do is configure your web.config file. If you are using a shared hosting environment, your IIS deployment is considered single server even though no doubt the actual servers are in a farm of some sort.See: MSDN Session-State Modes