Using Session State

Release 1.3 - ...

When using sessions in a web page, you must always make a call to the session.enable viper to enable sessions for an item. If a sessions is enabled or disabled is registered on a per item basis. Once sessions are enabled for an item (which is done by requesting that item and executing the session.enable viper in that request), sessions can no longer be disabled for that item.

Because Asp.Net does not allow multiple session requests from the same client at the same time, it is recommended that you enable sessions for as little items as possible. Try to avoid using sessions in requests to Javascript, Css of images because when multiple requests that use sessions are made at the same time, these requests will be serialized which means that are handled one after another instead of being handled at the same time. This will seriously impact the performance of your site.

If an item is requested for the first time, Smartsite does not know in advance if the item needs sessions or not. Because sessions cannot be enabled during a request, Smartsite will always enable sessions the first time an item is requested. When the request has completed, Smartsite knows if the session.enable viper was called or not and will use that information for all future requests to that item.

Starting with iXperion 1.2, there is a CTFP "EnableSessions" that can be set on the Nr field of a content type. When set to false, you can disable sessions for this content type altogether. This way you can avoid having sessions for the first request. Once disabled, sessions can longer be used for this content type.

Because Smartsite uses the Asp.Net Session object, the values in the session are accessible from both Smartsite items and Aspx pages. Sessions are currently not usable in Asp.Net Masterpages that are stored in Smartsite items.

Session state in Preview and AIM

Until 1.3, when previewing items that use sessions from the CMS Manager, you had to take extra measures, such as described in this article. If you didn't, you got the following exception:

Unable to use sessions because the item is not rendered by Asp.Net. 
You are probably previewing an item that uses sessions.
This is not supported.

From 1.3 onwards, previewing items with sessions has gotten a lot easier:

Silent Session Access

An appSettings value, 'SilentSessionAccess', is introduced for this.

Smartsite SXML CopyCode image Copy Code
<add key="SilentSessionAccess" value="true"/> 


After setting 'SilentSessionAccess' to 'true', no errors will be raised you can simply use a default value in session.get().

Smartsite SXML CopyCode image Copy Code
{session.get(firstRequest, default=datetime.now())}
 

The same fix is applicable to AIM scanning. During AIM scanning, no session state is available.