Asp.net - Do changes to session objects persist?

后端 未结 4 1028
半阙折子戏
半阙折子戏 2021-01-18 06:06

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

UserSession TheSession = HttpContext.Current.Session[\"UserSes         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 06:57

    Yes it is the same object. It is very easy to see in the following example:

    Session["YourObject"] = yourObject;
    yourObject.SomeProperty = "Test";
    var objectFromSession = (YourObjectType)(Session["YourObject"]);
    Response.Write(objectFromSession.SomeProperty);
    

    The Write will display: Test

提交回复
热议问题