ASP.NET:会话对象是我可接受的静态变量解决方案吗?

发布于 2024-11-15 01:47:55 字数 307 浏览 4 评论 0原文

我已经阅读了有关此主题的多个主题,并且需要对我在书中读到的几句话进行一些澄清:

如果您在进程中存储会话状态,则您的应用程序不可可扩展。其原因是 Session 对象存储在一台特定服务器上。因此在进程中存储会话状态不适用于网络场

  1. 第一句中的“可扩展”是什么意思?
  2. 第三句是否意味着如果我的应用程序驻留在共享网络主机上,我不应该使用 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.

  1. What does "scalable" in the first sentence mean?
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼泪也成诗 2024-11-22 01:47:55

1:

这种意义上的可扩展性

系统、网络或流程以优雅的方式处理不断增长的工作量的能力,或其扩展以适应这种增长的能力。[

2:

使用会话服务器或在 SQL Server 中存储会话,如下所述< a href="http://msdn.microsoft.com/en-us/library/ms178586.aspx" rel="nofollow">此处。

1:

Scalability in this sense:

the ability of a system, network, or process, to handle growing amounts of work in a graceful manner or its ability to be enlarged to accommodate that growth.[

2:

Use a session server or store sessions in SQL Server, which are described here.

掌心的温暖 2024-11-22 01:47:55

ASP.NET 可以将应用程序的所有组合会话信息(“会话状态”)存储在服务器端的 3 个可能位置(客户端 cookie 也是可能的,但这是一个不同的情况):

  • “InProc”(处理中)这意味着在附加到 asp.net 工作进程的 IIS 服务器上的内存中,
  • “StateServer”是一个单独的进程,可以被多个 IIS 服务器访问,但仍将会话状态存储在内存中,而
  • “SQLServer”则存储会话SQL Server 中的状态 数据库。

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):

  • "InProc" (In Process) which means in memory on the IIS server attached to the asp.net worker process,
  • "StateServer" which is a separate process that can be accessed by multiple IIS servers but still stores the Session state in memory, and
  • "SQLServer" which stores the Session state in a SQL Server database.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文