当请求从用户会话中获取对象时,是否会加载整个会话?
我试图了解何时可以将某些对象放入用户会话中,并且想知道如何存储会话以及如何从中检索值。如果我请求从会话状态中提取密钥 A,它还会读取密钥 B 吗?
我知道视图状态存储为一个大对象,并且我不会假设它完全加载后就可以从我的代码中访问它。这对于会话状态数据是否类似,还是仅加载从服务器请求的密钥。
因此,如果我的状态是 20KB,并且我想从中获取 5KB 的值,那么它会读取全部 20KB 还是只读取我需要的 5KB?
I'm trying to understand when I can put certain objects into a users session and am wondering how the session is stored and values retrieved from it. If I make a request to pull Key A from the session state will it also read Key B?
I know that viewstate is stored as one big object andn I am going ot assume that it is then accessed from my code once it's been entireely loaded. Is this similar for session state data or does it only load the keys that are requested form the server.
So if my state is 20KB and I want to get a value that's 5KB from it will it read all 20KB or just the 5KB that I need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,会话状态存储在内存中,直到会话过期(给定用户处于不活动状态的一段时间)。视图状态在请求之间根本不存储,而是实际上作为隐藏表单字段发送到页面。该数据将在后续请求时发送回服务器。
为了回答您的问题,默认行为是整个会话已加载,因此无论您是否实际访问它,它都在那里并在内存中。
但是,有多种管理此选项的选项,您可以在这里找到一个很好的参考:
http://msdn.microsoft.com/en-us/library/z1hkazw7.aspx
By default, session state is stored in memory until the session expires (a period of inactivity from a given user). The view state is not stored at all between requests, but is actually sent to the page as a hidden form field. This data is sent back to the server on subsequent requests.
To answer your question, the default behavior is that the entire session is ALREADY loaded so whether or not you actually access it, it is there and in memory.
There are several options for managing this however, and you can find an excellent reference here:
http://msdn.microsoft.com/en-us/library/z1hkazw7.aspx
默认情况下,用户会话存储在内存中。您可以将其配置为存储在数据库中,但它是序列化的,并在重新实例化时完全读出。
所以,是的,如果您的用户会话中有 20KB 的数据,它将始终使用 20KB 的内存。
By default, a users session is stored in memory. You could configure it to be stored in the database, but it is serialized, and read out completely when re-instantiated.
So yes, if you have 20KB worth of data in your users session, it will always use 20KB of memory.