C# – ASP.NET Session State Server – Saving Unserialized Data


As you know, in ASP.NET, you can store session data in one of following three modes:

  • InProc
  • Session State
  • SQL Server

For InProc mode, you can store any kind of data objects even it's not serializable. However, in Session State and SQL Server modes, you can only store serialized data.

In my project, I have a ready made portal which use "InProc" mode to store its session. I need to use Session State instead due to some scalability and failure handling issues.

The problem that this portal is internally storing unserialized objects in the session context (i.e The stored objects doesn't implement ISerializable interface). I have no access to their code. Is there any work around so that I can be able to store the session objects in State Server without changing their code. I still have access to their web.config file if this would help in any kind.

Best Solution

AFAIK, the simple answer is no. If you don't mind changing your code, you could inject a wrapper object between the actual object and yours, and make your wrapper deal with serializing the wrapped object (essentially as a serialization surrogate) - but by then it would almost be easier to simply re-write the code...

What sort of objects are they? Typically, objects for session-state would be simple data classes, so there shouldn't be too much issue serializing them?

Related Question