I have an object that looks like this:
public class MySession{
string UserID {get;set;}
List<Object1> ListOfObject1 {get;set;}
List<Object2> ListOfObject2 {get;set;}
....
several other lists....
}
The advantage of doing this is that I can write something like “on page load” MySession TheSession = Session["TheSession"] as MySession; and then access the session’s properties more easily in code.
For now, this works with InProc session but I’m looking to move to SQL Server session.
What’s the best way to make this change? I’m thinking of serializing the MySession object into a json string and then letting SQL Server session save the session as a string. Then, when I reload the session, simply load the json string and deserialize it.
I don’t know if this is the most efficient way to do it.
Thanks for your suggestions.
All you need to do is make
MySessionand all related classes[Serializable](binary serialization).ASP.Net will automatically serialize it for you.