Using object after it has been put in Session

A

Aleksey Dmitriyev

I am using Session property for my own serializable objects. The code
snippet is below:

// C# ASP.NET code behind

private void btnRun_Click(object sender, System.EventArgs e)
{
MyClass myObj = new MyClass("abc", 99);

Session["key1"] = myObj;

myObj.SetValues("xyz", 123 );
myObj.m_inner = new MyClassInner("my inner obj", 555);
}

private void btnGetState_Click(object sender, System.EventArgs e)
{
MyClass myObj = (MyClass)Session["key1"];
if (myObj != null) lblData.Text = myObj.ToString();
}

It works fine in all three modes "InProc", "StateServer", "SQLServer". I
don't see any problems with modifying object after it was put in the
session. However someone mentioned that it might cause some problems. Can
anyone think of any problems with that?

Another question about how MS implements their session state management. It
looks like they keep references to all object in an internal in-proc
dictionary until the end of request and then they persist the whole
dictionary? Does anyone know details? On what event it the dictionary is
serialized?

Thanks,
A.D.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top