ASP.NET会话变量 [英] ASP.NET session variables

查看:163
本文介绍了ASP.NET会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个会话变量:ID。是否有过一种可能性,即在同一台PC上的两个浏览器可以共享同一个会话变量和更新,因此产生随机的结果。我希望在那里总是有两套独立的会话变量的两个单独的会话。

I have a session variable: ID. Is there ever a possibility that two browsers on the same PC could share the same session variable and update it, therefore producing random results. I would expect there to always be two separate sessions with two separate sets of session variables.

我研究这一点,我来翻过以下网页,这表明有会话锁从prevent这happening:http://odeto$c$c.com/blogs/scott/archive/2006/05/20/session-state-uses-a-reader-writer-lock.aspx.我有一个ASP.NET应用程序,并有暗示这可能会发生随机的结果。

I have researched this and I have come accross the following web page, which suggests that there are session locks to prevent this from happening:http://odetocode.com/blogs/scott/archive/2006/05/20/session-state-uses-a-reader-writer-lock.aspx. I have an ASP.NET application and there are random results suggesting that this could be happening.

我会产生一些code。如果要求。

I will produce some code if requested.

UPDATE 19:51
蒂姆梅多拉表示:使用相同的会话ID相同的浏览器类型的两个实例。这是否意味着,如果用户打开一个浏览器,然后关闭它(因为它需要很长时间才能打开),然后打开另一个浏览器(在另一个窗口),那么可以使用相同的会话ID,并在窗口1会话变量被复制窗2?

UPDATE 19:51 Tim Medora says: "two instances of the same browser type using the same session ID". Does this mean that if a user opens one browser and then closes it (because it takes too long to open) and then opens another browser (in another window) then the same session ID could be used and the session variables in window 1 are copied for window 2?

更新19:35 24/10/2012
蒂姆梅多拉说:不过没有在同一个浏览器两个选项卡,或使用相同的会话ID相同的浏览器类型的两个实例的非常现实的可能性。请问会话信息在这些情况下分开。例如,如果用户打开浏览器,然后将其关闭(响应加载之前),然后用一组不同的会话变量打开相同的窗口,则是有一个风险,即会话A和会话B具有相同的会话变量。

UPDATE 19:35 24/10/2012 Tim Medora says: "However there is a very real possibility of two tabs in the same browser, or two instances of the same browser type using the same session ID". Will the session information be separate in these cases. For example, if a user opens a browser and then closes it (before the response has loaded) and then opens the same window with a different set of session variables then is there a risk that session A and session B have the same session variables.

推荐答案

随机碰撞的可能性极低。

The possibility of a random collision is extremely low.

但是,现在使用相同的会话ID 1 会话ID也可以重复使用,增加了混乱。

However there is a very real possibility of two tabs in the same browser, or two instances of the same browser type using the same session ID1. Session IDs may also be reused, adding to the confusion.

这是否意味着,如果用户打开一个浏览器,然后将其关闭
  (因时间过久,打开),然后打开另一个浏览器(以
  另一个窗口),则可以使用相同的会话ID和会话
  在窗口1变量被复制的窗口2?

Does this mean that if a user opens one browser and then closes it (because it takes too long to open) and then opens another browser (in another window) then the same session ID could be used and the session variables in window 1 are copied for window 2?

是的,会话ID可重复使用,在同一会话可能被激活。我做了一个快速实验Chrome和我能够复制URL(使用会话)新选项卡和浏览器的新实例,以及在同一会话依然活跃。

Yes, the session ID may be reused and the same session may be active. I did a quick experiment with Chrome and I was able to copy a URL (which uses Session) to new tabs and new instances of the browser, and the same session stayed active.

然而,会话变量不是的复制的新窗口;它们是相同的值。

However, the session variables are not copied for the new window; they are the same values.

锁定会话仅仅意味着两位作家不能在完全相同的时间更新。更具体地,一个锁放置在会话从直到请求结束的请求的开始;只有一个可以写在这期间改变它。但是那段时间通常非常小,(而锁定prevents一些问题),它没有prevent两个不同的来源在不同时间改变了相同的数据。

Locking Session only means that two writers can't update it at exactly the same time. More specifically, a lock is placed on Session from the beginning of the request until the end of the request; only one write can alter it during that period. But that period of time is usually very small, and (while the locking prevents some issues) it doesn't prevent two different sources from altering the same data at different times.

,以减少冲突的一种方法是使用唯一会话密钥。比方说,一个用户(在同一个会话)打开并编辑两个不同的记录。如果有的ActiveRecord的会话密钥,用于数据损坏/失配的可能性非常高。然而,如果每一个页面存储在隐藏字段的唯一密钥,该唯一密钥然后可用于检索会话的适当的值,并且每个值可以离散地被操纵

One way to minimize collision is to use unique session keys. Let's say a user (in the same session) opens two different records for editing. If you have a session key of "ActiveRecord", the probability for data corruption/mismatch is very high. However, if each page stores a unique key in a hidden field, that unique key can then be used to retrieve the appropriate value from Session, and each value can be manipulated discretely.

在换句话说,独特的按键让您在同一项目在同一时间放心地开着两个不同的实例。这确实的的有两个窗口同时编辑同一个项目prevent问题。虽然他们将有单独的密钥,当数据被提交的最终结果将可能是不理想的。

In other words, unique keys allow you to safely open two different instances of the same item at the same time. This does not prevent issues with two windows editing the same item at the same time. Though they will have separate keys, the end result will probably be undesirable when the data is committed.

1 - 这似乎是所有现代浏览器的情况下,但我不能肯定地说,这是的总是的情况。欢迎参考。

1 - this seems to be the case in all modern browsers, but I can't definitively say that it is always the case. Would welcome a reference.

这篇关于ASP.NET会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆