ASP.NET Session size limitation

Here’s a few notes about Session state:

  • InProc (mode="InProc") session state is limited to the amount of memory available to the worker process. Only object references are stored, not the objects themselves.

Out of process state management serialises objects before persisting them:

  • Out of Process state management using the session state server (mode="StateServer") is limited to the amount of memory available to the state service.

  • Out of Process state management using SQL Server (mode="SQLServer") is bound only by the maximum size of the SQL image data type or the maximum permitted size of the database.

Obviously there still has to be enough memory available to the worker process to be able to pull an out of session object back into memory and re-hydrate for the duration of the http request.

As I mentioned previously, out of process state management serialises objects before persisting them.

This means that objects must be serialisable which excludes, for example, XmlDocument or anything that inherits from MarshalByRef.

Attempting to serialise objects of this sort will result in the following exception:

Unable to serialize the session state. In ‘StateServer’ and
‘SQLServer’ mode, ASP.NET will serialize the session state objects,
and as a result non-serializable objects or MarshalByRef objects are
not permitted. The same restriction applies if similar serialization
is done by the custom session state store in ‘Custom’ mode.

Leave a Comment