加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-core – asp.net核心会话不是用户特定的吗?

发布时间:2020-12-16 06:50:34 所属栏目:asp.Net 来源:网络整理
导读:当我使用经典ASP.NET或甚至旧的Web表单时,HttpContext.Current.Session是特定于用户的.因此,当用户发出请求时,他会收到会话cookie,然后继续该会话仅属于该用户.因此,两个不同的用户可以在其各自的会话中具有相同名称的会话密钥. 我正在阅读ASP.NET Core中的
当我使用经典ASP.NET或甚至旧的Web表单时,HttpContext.Current.Session是特定于用户的.因此,当用户发出请求时,他会收到会话cookie,然后继续该会话仅属于该用户.因此,两个不同的用户可以在其各自的会话中具有相同名称的会话密钥.

我正在阅读ASP.NET Core中的会话文档,看起来它与旧的asp.net具有相同的概念,但文档中的某些注释令人困惑.
here它说

Session storage relies on a cookie-based identifier to access data
related to a given browser session (a series of requests from a
particular browser and machine). You can’t necessarily assume that a
session is restricted to a single user
,so be careful what kind of
information you store in Session. It is a good place to store
application state that is specific to a particular session but which
doesn’t need to be persisted permanently

它也说here

Session is non-locking,so if two requests both attempt to modify the
contents of session,the last one will win. Further,Session is
implemented as a coherent session,which means that all of the
contents are stored together. This means that if two requests are
modifying different parts of the session (different keys),they may
still impact each other.

所以,让我说我有User1登录并在我设置的一些动作

`Session.SetInt32("key1",123)`

现在User2从其他一些机器登录,并根据我设置的一些动作

`Session.SetInt32("key1",999)`

问题1
这会覆盖User1的密钥吗?

另请注意here说

ASP.NET ships with several implementations of IDistributedCache,
including an in-memory option (to be used during development and
testing only)

问题2
我可以在生产中使用的IDistributedCache的其他实现是什么?

解决方法

问题1.

不,修改会话密钥的一个用户不会覆盖不同用户的密钥.由于创建了.AspNetCore.Session cookie,因此会话对每个访问者/用户都是唯一的.

根据该唯一标识符存储所有Session.Set调用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读