Generally, ASP. NET stores session states in three ways: inproc, StateServer, and sqlserver. In this case, you can use a syntax similar to this to store the session state: session ["key"] = Val. Val can be any type of object.
However, if StateServer or sqlserver is used, the Val type must be a serializable type, because the ASP. NET application must serialize the object when data is exchanged between status servers. If Val is not serializable (the private domain/attribute is not specified and the custom serialization feature is not specified), the following exception occurs during runtime:
"/"ApplicationProgramServer error.
Unable to serialize session status. In "StateServer" Or "Sqlserver" Mode, ASP. NET The session state object is serialized, so it is not allowed to use objects that cannot be serialized or Marshalbyref Object. If the custom session status is stored in "Custom" If similar serialization is executed in the mode, the same restrictions apply.
There are several solutions:
1. Try to use basic types of objects to store data
2. Only public domains/attributes are used for custom types.
3. Implement serialization for custom types
......
the advantages and disadvantages of these methods are not described. I was lazy and used the first one.