简体   繁体   English

在经典的ASP应用程序中,使用会话或cookie来实现跨页数据持久性更好吗?

[英]In a classic ASP application, is it better to use a session or cookie for cross-page data persistence?

I have inherited a fix on a classic ASP application where we want to store some user session-specific data to persist across page loads/their session, and need a bit of a refresher. 我继承了一个经典ASP应用程序的修复程序,该程序中我们要存储一些特定于用户会话的数据,以在页面加载/会话期间保持不变,并且需要一些刷新。

In the past I have simply used Session variables - ie. 在过去,我仅使用Session变量-即。 Session("SomeVar") = SomeVal . Session("SomeVar") = SomeVal

In IIS on the production box, I noticed that ASP / Session Properties / Enable Session State = false. 在生产框中的IIS中,我注意到ASP /会话属性/启用会话状态= false。 Setting this to True allowed me to successfully begin using session variables. 将此设置为True可让我成功开始使用会话变量。

I don't want to consume any more resources than necessary on the server. 我不想消耗服务器上不必要的资源。 In the past, I believe that I was under the delusional misconception that session variables in classic ASP were stored on the client side. 过去,我相信我是在幻想的误解之下,经典ASP中的会话变量存储在客户端。 Revisiting this now - the data is retained on the server side. 现在重新访问-数据保留在服务器端。

The string I am saving is a GUID, for roughly 3000 connected clients. 我保存的字符串是一个GUID,大约可连接3000个客户端。

What kind of server impact am I looking at if I implement this, and would using client-side cookies be a better option? 如果实现此功能,我会看到什么样的服务器影响,并且使用客户端cookie会是更好的选择吗?

Multiple servers/server farm? 多个服务器/服务器场? If so you might run into trouble using Session if you load balancer is not set to be "sticky" and send you to the same server each time. 如果是这样,并且您的负载均衡器未设置为“粘性”,并且每次将您发送到同一台服务器,则使用Session可能会遇到麻烦。 Can me a real headache to debug so becareful. 调试时要小心一点,我真的会头疼吗?

Lets analyse this a bit, a GUID takes about 40 characters as a string hence in Unicode thats 80 bytes, lets call it 100 bytes. 让我们对此进行分析,一个GUID大约需要40个字符作为字符串,因此在Unicode中就是80字节,我们称它为100字节。 100 * 3000 = 300KB. 100 * 3000 = 300KB。 Can server spare 300K for this? 服务器可以为此节省300K吗? I think the server already in trouble if the answer were no. 如果答案是否定的,我认为服务器已经遇到麻烦了。

However there are other impacts to enable session state. 但是,启用会话状态还有其他影响。 When sessions are enabled ASP adds its own cookie to the client which in size terms is probably equivalent to the one you would need if you were storing your GUID as cookie instead of in the session. 启用会话后,ASP将向客户端添加自己的cookie,从大小上讲,它等效于将GUID存储为cookie(而不是在会话中)时需要的cookie。 Its worth noting that this session ID stored in the cookie uses an algorithm which some say is more predictable (I haven't got any evidence of that myself). 值得注意的是,存储在cookie中的该会话ID使用了一种算法,有人说它更可预测(我自己对此没有任何证据)。 Hence if you are using the GUID as some form of authorization then storing the GUID as cookie directly may be better. 因此,如果您将GUID用作某种形式的授权,则将GUID直接存储为cookie可能会更好。

There is a further significant change that happens when Session state is enabled. 启用会话状态后,还会发生进一步的重大变化。 ASP requests from a client must be processed serially, the server will not process multiple requests from the same client in parallel. 来自客户端的ASP请求必须串行处理,服务器将不会并行处理来自同一客户端的多个请求。 This is because the Session object is single threaded and since each request from a client needs access to it the requests cannot be processed at the same time. 这是因为Session对象是单线程的,并且由于来自客户端的每个请求都需要对其进行访问,因此无法同时处理这些请求。

That last point could have significant impact on the existing behaviour and performance that a client sees especially if AJAX techniques, multiple IFrames or other techniques which result in simultaneous ASP requests being sent to the server are being used. 最后一点可能会对客户端看到的现有行为和性能产生重大影响,尤其是如果正在使用AJAX技术,多个IFrame或导致同时向服务器发送ASP请求的其他技术。

Hence for the requirement you have my choice would be to store the GUID in a cookie and leave session state turned off. 因此,根据要求,您可以选择将GUID存储在cookie中,并使会话状态保持关闭状态。

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

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