asp.net核心会话不是特定于用户的吗? [英] Is asp.net core session not user specific?
问题描述
当我使用经典的ASP.NET甚至使用旧的Web表单时,HttpContext.Current.Session是特定于用户的.因此,当用户发出请求时,他会收到会话cookie,然后该会话仅属于该用户.因此,两个不同的用户可以在各自的会话中使用相同名称的会话密钥.
When i was working with classic ASP.NET or even with old web forms the HttpContext.Current.Session was User specific. So when user makes the request he receives the session cookie and then onward that session belongs to that user only. So two different users can have session key with the same name in their respective session.
我正在阅读ASP.NET Core中有关会话的文档,看起来它与旧的asp.net具有相同的概念,但是文档中的某些注释令人困惑.
此处说
I am reading the documenation on session in ASP.NET Core and looks like it has the same concept as old asp.net however certains notes in the documentation is confusing.
here it says
会话存储依赖于基于cookie的标识符来访问数据与给定的浏览器会话相关(来自特定的浏览器和机器).您不一定要假设会话仅限于单个用户,因此请注意哪种您存储在会话中的信息.这是一个存放的好地方特定于特定会话的应用程序状态,但是不需要永久保存
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
也此处它说
会话未锁定,因此如果两个请求都尝试修改会议内容,最后一个将获胜.此外,会话是作为一个连贯的会议实施,这意味着所有内容存储在一起.这意味着如果有两个请求修改会话的不同部分(不同的键),它们可能仍然互相影响.
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并进行了一些设置
so lets say i have User1 logged in and upon some action i set
`Session.SetInt32("key1", 123)`
现在User2从其他计算机登录,并且我设置了某些操作
now User2 logs in from some other machine and upon some action i set
`Session.SetInt32("key1", 999)`
问题1
这会覆盖User1的密钥吗?
Question 1
Will this overwrite User1's key?
还请注意此处说
ASP.NET附带了IDistributedCache的几种实现,包括内存选项(将在开发和仅限测试)
ASP.NET ships with several implementations of IDistributedCache, including an in-memory option (to be used during development and testing only)
问题2
我可以在生产中使用的IDistributedCache的其他实现是什么?
Question 2
What are the other implementation of IDistributedCache that i can use in production?
推荐答案
对于问题1.
否,一个用户修改会话密钥不会覆盖另一个用户的密钥.由于创建了.AspNetCore.Session cookie,因此该会话对于每个访问者/用户而言都是唯一的.
No, one user modifying a session key will not overwrite a different user's key. The session is unique to each visitor/user because of the .AspNetCore.Session cookie that is created.
所有Session.Set调用都将根据该唯一标识符进行存储.
All of the Session.Set calls get stored per that unique identifier.
这篇关于asp.net核心会话不是特定于用户的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!