How to use sessions while previewing items using the manager (-1.2).

Release 1.01 - Release 1.2

When previewing an item in the manager that uses sessions the following error occurs: "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 yet supported."

You can work around this problem using PageTranslations.


Add the following code to  a 'System Translation' and implement it on your rendertemplate's initialization. (e.g. inside an 'init()' system translation)

Smartsite SXML CopyCode image Copy Code
<se:pagetranslations id="session">
      <se:collection>
            <se:member name="get(key, default)">
                  <se:if expression="!request.ispreview()">
                        <se:then>
                              {translation.setresult(session.get(translation.arg(key)))}
                        </se:then>  
                        <se:else>
                              {translation.setresult(translation.arg(default))}
                        </se:else>
                  </se:if>
            </se:member>
            <se:member name="set(key, value)">
                  <se:if expression="!request.ispreview()">
                        <se:then>
                              {session.set(translation.arg(key),translation.arg(value))}
                        </se:then>  
                  </se:if>
            </se:member>
      </se:collection>
</se:pagetranslations>

Now use this syntax if you want to use sessions and be able to preview your items:

Syntax Description
translation.session.set(Key, Value) Sets the specified client session state, does nothing in case of a preview.
translation.session.get(Key, Default) Gets the specified client session state, returns default in case of a preview.
translation.session.get(Key) Gets the specified client session state, returns null in case of a preview.