Does the ASP.Net Session variable store the actual value or just a reference?

I have the following code where I am collecting data stored in session in a local variable and updating the datatable. The next time I access the session, the updated values ​​are updated. (in my case, the first line was removed, which was selected for the objTable1 variable):

 protected void Page_Load(object sender, EventArgs e)
    {
        DataTable objTable = (DataTable)Session["dTable"];

        objTable.Rows[0].Delete();

        DataTable objTable1 = (DataTable)Session["dTable"];

    }

      

I thought local variables make a copy of the session variable and update it without updating the session variable.

Sincerely.

+3


source to share


1 answer


You are dealing with a reference to an object in a session, so this is how it should work.



If you want to work with another object, you must clone the object in the session to work, and then replace the one stored in the session with the clone if you want to keep any changes.

+1


source







All Articles