views:

482

answers:

1

It looks like the value in my session object changes when I modify a local variable set from session.

Setup:

.net 2.0

BasePage retrieves a complex object from session , casts it, and stores it in a class level variable. Child Page uses class level variable to do play out some optional scenarios. User decides to not keep changes, session object is not updated from variable, however when you retrieve the value from session it contains those unsaved changes.

In debug mode looking at the the session object, it changes at the same time the local object changes.

Thanks!

+1  A: 

You're returning a reference to the object in the session so this is how it should work. If you want to work with a different object, you should make a clone of the object in the session to work with, then replace the one stored in the session with the clone if the user decides to accept the changes.

tvanfosson
Did this change from .net 1 to 2?So if I have the following:myObj temp = Session["myStuff"] as myObj;temp.name = "test";temp = Session["myStuff"] as myObj;I was almost positive I've used this in the past to reset changes to the local variable.