简体   繁体   English

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

[英]How does Session_Start() work in server farm?

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? OnSessionStart / Session_Start 事件是否仍然仅在服务器场环境中触发一次(总共),或者由于请求由多个服务器处理,它是否可以在每个服务器上触发一次?

ASP.NET / IIS6 or 7 ASP.NET / IIS6 或 7

It should not be assumed that the server is using Sticky Sessions.不应假定服务器正在使用粘性会话。

With a default installation of IIS the answer is "no" -- the Session_Start will in general fire multiple times.对于 IIS 的默认安装,答案是“否”——Session_Start 通常会触发多次。 A client will create a new Session on each different server it hits.客户端将在它命中的每个不同服务器上创建一个新的 Session。 The same thing goes if you are using the Web Garden option in IIS.如果您在 IIS 中使用 Web Garden 选项,也会发生同样的事情。

If you don't depend on Session and you have a server farm you are usually best off disabling Session state completely.如果您不依赖 Session 并且您有一个服务器场,您通常最好完全禁用 Session state。 Here is how you do it: http://support.microsoft.com/kb/306996这是您的操作方法: http://support.microsoft.com/kb/306996

If you do depend on Session your best option is probably the ASP.NET State Server Service.如果您确实依赖 Session,那么您最好的选择可能是 ASP.NET State 服务器服务。 All the servers in your farm will use a single server for Session state, and that will ensure that Session_Start only fires once.您场中的所有服务器都将为 Session state 使用单个服务器,这将确保 Session_Start 仅触发一次。 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有关设置的大量背景和详细信息,请阅读以下内容(查找“状态服务器模式”以获得具体说明): http://aspdotnetdevs.blogspot.com/2008/12/aspnet-session-state-and-modes.html

In addition to Thomas: It depends on your Session State settings.除了 Thomas:这取决于您的 Session State 设置。

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

If you use mode="InProc" you'll get multiple Session and SessionStart events, 1 per visited server.如果您使用mode="InProc"您将获得多个 Session 和 SessionStart 事件,每个访问的服务器 1 个。

In the other modes (StateServer or SqlServer) you'll get 1 session and 1 SessionStart.在其他模式(StateServer 或 SqlServer)中,您将获得 1 个 session 和 1 个 SessionStart。 You will not get a SessionEnd event at all.您根本不会收到 SessionEnd 事件。

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. 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.它让这台服务器照顾您的 state,而不是确保每个 session 只应调用一次 OnSessionStart,并且无需始终将所有请求 Z34D1F91FB2E514B8576FAB1A75A89 都返回到服务器。

The main downside of using a single server for maintaining session state is that you no longer have an OnSessionEnd event.使用单个服务器维护 session state 的主要缺点是您不再有 OnSessionEnd 事件。

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.我的理解是,一旦请求到达场中的服务器,同一客户端的所有即将到来的请求都应重定向到场中的同一台服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM