Session_Start() 在服务器场中如何工作?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于 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
除了 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.
在场中,您将使用 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.
我的理解是,一旦请求到达场中的服务器,同一客户端的所有即将到来的请求都应重定向到场中的同一服务器。
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.