简体   繁体   English

在多Web服务器场中,会话状态如何工作?

[英]In a multi web server farm, how does session state work?

CASE 1: StateServer 案例1:StateServer

<system.web>
   <sessionState     mode="StateServer"     stateConnectionString="tcpip=127.0.0.1:42626"     sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"     cookieless="false"     timeout="20"   />
 ... 
</system.web>

CASE 2: SQL Server 案例2:SQL Server

<sessionState   mode="SQLServer"   stateConnectionString="tcpip=127.0.0.1:42626"   sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"   cookieless="false"   timeout="20" /> 

Question: 1. In case 1 and 2 appropriate location of sql or state server have to be configured in web.config for each of the web server in farm. 问题:1.在情况1和2中,必须在web.config中为服务器场中的每个Web服务器配置sql或状态服务器的适当位置。

  1. Can we have some servers configured as state and some as sql? 我们可以将某些服务器配置为状态,将某些服务器配置为sql吗?

  2. Can we have some cookieless and some as withcookie 我们可以有一些无cookie的和有cookie的吗

  3. Suppose if we use only <sessionState cookieless="true" /> , then by default which of the modes is used? 假设如果仅使用<sessionState cookieless="true" /> ,那么默认情况下使用哪种模式? Can this be done in a multiserver farm, or is it necessary to specify the IP? 可以在多服务器场中完成此操作,还是必须指定IP?

1.) Can we have some servers configured as state and some as sql? 1.)我们可以将某些服务器配置为状态,将某些服务器配置为sql吗?

No, you should not. 不,你不应该。 Suppose when a user makes a request, then one of the server from your Web Farm will store the session in a StateServer. 假设当用户发出请求时,Web场中的一台服务器会将会话存储在StateServer中。 now in case the same user makes another request ( by clicking some links etc...), then image what will happen if your load balancer send this request to the 2nd Web server ? 现在,如果同一用户又发出另一个请求(通过单击一些链接等),然后想象如果您的负载均衡器将此请求发送到第二台Web服务器会发生什么? There will be NO session for the same user as you configured SqlServer mode for the same and the session for the user was stored on a state server on First request. 与您为SqlServer模式配置的用户相同,该用户将没有会话,并且该用户的会话在首次请求时存储在状态服务器上。

2.) Can we have some cookieless and some as withcookie ? 2.)我们可以有一些无cookie的和无cookie的吗?

Again NO, for a very similar understanding as pointed above. 再次否,对于上面指出的非常相似的理解。 One of the server will use cookies to track the session and the other one Cookieless ( hence URI ) to track the same session and thus, if the request gets forwarded to different servers, NO session will be detected. 其中一台服务器将使用Cookie跟踪会话,另一台服务器将使用Cookieless(因此称为URI)跟踪同一会话,因此,如果将请求转发到其他服务器,则不会检测到会话。

3.) Suppose if we use only <sessionState cookieless="true" /> , then by default which of the modes is used? 3.)假设如果仅使用<sessionState cookieless="true" /> ,那么默认情况下将使用哪种模式? Can this be done in a multiserver farm, or is it necessary to specify the IP? 可以在多服务器场中完成此操作,还是必须指定IP?

Understand that this setting: cookieless="true|false" , is just used to TRACK the session for a Particular user between the Client side and server side. 了解此设置: cookieless="true|false" ,仅用于跟踪客户端和服务器端之间特定用户的会话。

The Actual session DATA is there stored on SqlServer/State Server, which is defined in your mode settings as: 实际会话数据存储在SqlServer /状态服务器上,在您的模式设置中定义为:

<sessionState  mode="StateServer|SqlServer" ... />

if you don't specify any mode setting, default value of InProc is used. 如果未指定任何mode设置,则使用InProc默认值。


Additional Note: The Cookie or the URI have a SessionID associated with them. 附加说明: Cookie或URI具有与之关联的SessionID SessionID is a unique string, used to TRACK individual visitor between visits to website. SessionID是唯一的字符串,用于在访问网站之间跟踪单个访问者。

As a result of cookieless="true" , SessionID will be embedded in all page URLs. 由于cookieless="true" ,因此SessionID将嵌入到所有页面URL中。 The drawback is that you'll end up with ugly URLs, which are not so good for SEO (search engine optimization) and visitor definitely will not remember it. 缺点是您将得到丑陋的URL,这些URL不太适合SEO(搜索引擎优化),并且访问者肯定不会记得它。 Here is an example URL of website which uses ASP.NET cookieless sessions: 这是使用ASP.NET无cookie会话的网站的示例URL:

http://samplewebsite.com/ ( 45f8c4zyybphaw2mt3dfgnjk4j )/Home.aspx http://samplewebsite.com/ (45f8c4zyybphaw2mt3dfgnjk4j)/Home.aspx

Bolded part represents session id, which is used to recognize a visitor. 粗体部分表示会话ID,用于识别访问者。

Your question is a bit vague. 您的问题有点含糊。 If you're hosting one app across multiple servers I would recommend sticking to one method. 如果您要在多个服务器上托管一个应用程序,我建议您采用一种方法。 What if one user first connects to a server with one mode , and the next request is handled by another one? 如果一个用户首先以一种mode连接到服务器,而下一个请求由另一种mode处理,该怎么办? The session state would not be accessible/known to the other server. 会话状态将不可被其他服务器访问/知道。

As to your questions, the documentation is really quite clear. 关于您的问题, 文档非常清楚。

cookieless does not affect mode . cookieless不会影响mode If you don't specify mode , the default is InProc . 如果不指定mode ,则默认值为InProc If cookieless is true , ASP will use the query string. 如果cookielesstrue ,则ASP将使用查询字符串。

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

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