Typically, ASP. NET storage session state is available in three ways--inproc, StateServer, and SQL Server. The most commonly used is the first, in which case a syntax like this can be used to store session state: session["Key" = val. Where Val can make any type of object.
However, if you use StateServer or SQL Server, the type of Val is required to be a serializable type, because the ASP.net application requires serialization of the object when the data is exchanged between state servers. If Val is not serializable (has a private domain/attribute and does not specify a custom serialization attribute), the following exception occurs at run time:
Server error in '/' Application.
--------------------------------------------------------------------------------
Unable to serialize session state. In either "StateServer" or "SQL Server" mode, ASP.net will serialize the session-state object, so objects that cannot be serialized or MARSHALBYREF objects are not allowed. The same restriction applies if the custom session state store performs a similar serialization in custom mode.
There are several ways to solve this problem:
1 use basic types of objects to store data as much as possible
2 Custom types use public domain/attribute only
3 Implementing serialization attributes for custom types
......
The advantages and disadvantages of several methods are not explained. I used the first kind of slack.