Asp.net - 不要修改会话对象持久化? [英] Asp.net - Do changes to session objects persist?

查看:131
本文介绍了Asp.net - 不要修改会话对象持久化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的会议期间举办的自定义对象UserSession,我访问这样的会话:

I'm using the session to hold a custom object UserSession and I access the session like this:

UserSession TheSession = HttpContext.Current.Session["UserSession"] as UserSession;

然后,在我的code,我修改TheSession的属性,这样

Then, in my code, I modify a property of TheSession like this

TheSession.Prop1 = some new value;

我的问题是这样的:当我改变的价值,它改变值在HttpContext.Current.Session会话[UserSession]或只是TheSession变量中,在这种情况下,我需要重新分配对象变量到会话。

My question is this: when I change the value, does it change the value inside the session that's in HttpContext.Current.Session["UserSession"] or just the TheSession variable, in which case I'd need to reassign the object variable to the session.

感谢。

推荐答案

标准会话供应商是一个简单的字典存储在内存中的对象。

The standard session provider is a simple dictionary that stores objects in memory.

您正在修改你把会话,这样的修改会持续同一个对象。结果
(除非您使用的是邪恶的可变结构

You're modifying the same object that you put in the session, so the modifications will persist.
(unless you're using an evil mutable struct)

这篇关于Asp.net - 不要修改会话对象持久化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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