Session_Start() 在服务器场中如何工作?

发布于 2024-07-13 23:14:25 字数 148 浏览 4 评论 0原文

OnSessionStart / Session_Start 事件在服务器场环境中是否仍然只触发一次(总共),或者由于请求由多个服务器处理,因此每个服务器最多可以触发一次吗?

ASP.NET / IIS6 或 7

不应假设服务器正在使用粘性会话。

Does the OnSessionStart / Session_Start event still only fire once (total) in a server farm environment, or since requests are handled by multiple servers, could it fire up to once per server?

ASP.NET / IIS6 or 7

It should not be assumed that the server is using Sticky Sessions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

北城半夏 2024-07-20 23:14:25

对于 IIS 的默认安装,答案是“否”——Session_Start 通常会触发多次。 客户端将在它访问的每个不同服务器上创建一个新会话。 如果您使用 IIS 中的 Web Garden 选项,也会出现同样的情况。

如果您不依赖于会话并且您有一个服务器场,那么您通常最好完全禁用会话状态。 操作方法如下:
http://support.microsoft.com/kb/306996

如果您确实依赖 Session,那么您最好选项可能是 ASP.NET 状态服务器服务。 您场中的所有服务器都将使用单个服务器作为会话状态,这将确保 Session_Start 仅触发一次。 有关设置的大量背景和详细信息,请阅读此内容(查找“状态服务器模式”以获取具体说明):
http://aspdotnetdevs.blogspot.com/2008/12 /aspnet-session-state-and-modes.html

With a default installation of IIS the answer is "no" -- the Session_Start will in general fire multiple times. A client will create a new Session on each different server it hits. The same thing goes if you are using the Web Garden option in IIS.

If you don't depend on Session and you have a server farm you are usually best off disabling Session state completely. Here is how you do it:
http://support.microsoft.com/kb/306996

If you do depend on Session your best option is probably the ASP.NET State Server Service. All the servers in your farm will use a single server for Session state, and that will ensure that Session_Start only fires once. For lots of background and detail on setup read this (Look for "State Server Mode" to get specific instructions):
http://aspdotnetdevs.blogspot.com/2008/12/aspnet-session-state-and-modes.html

娇柔作态 2024-07-20 23:14:25

除了 Thomas:这取决于您的会话状态设置。

在 web.config 中,

如果您使用 mode="InProc" 您将获得多个 Session 和 SessionStart 事件,每个访问的服务器 1 个。

在其他模式(StateServer 或 SqlServer)中,您将获得 1 个会话和 1 个 SessionStart。 您根本不会收到 SessionEnd 事件。

In addition to Thomas: It depends on your Session State settings.

in web.config, <sessionState mode="" >

If you use mode="InProc" you'll get multiple Session and SessionStart events, 1 per visited server.

In the other modes (StateServer or SqlServer) you'll get 1 session and 1 SessionStart. You will not get a SessionEnd event at all.

苏大泽ㄣ 2024-07-20 23:14:25

在场中,您将使用 Sql Server 或状态服务器来管理场中所有服务器的会话状态。 它让这台服务器负责管理您的状态,从而确保每个会话仅调用一次 OnSessionStart,并且无需始终将所有请求返回到同一服务器。

使用单个服务器维护会话状态的主要缺点是不再有 OnSessionEnd 事件。

In a farm, you would be using either Sql Server or a State Server for managing session state across all the servers in the farm. It is having this single server looking after your state than ensures that OnSessionStart should only be called once per session and there is no need to have to always have all the requests go back to the same server.

The main downside of using a single server for maintaining session state is that you no longer have an OnSessionEnd event.

冷月断魂刀 2024-07-20 23:14:25

我的理解是,一旦请求到达场中的服务器,同一客户端的所有即将到来的请求都应重定向到场中的同一服务器。

my understanding is that once a request reach a server in the farm ,all of the upcoming requests of the same client should be redirected to the same server in the farm.

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