Is there a common existing approach in Cobalt Website for storing data within session?

As new projects are developed which need to persist some data within session, is there some documentation or guidelines for how to store data in session from Cobalt Website module?

Best Answer

  • Here are a few general guidelines I can think of that we've used in the past... Things which should go in Website Session: - Values which are only used by Website - Values which are mutable throughout the lifetime of the user's session - Values which can not be added to URL parameters or would represent a security risk if they were exposed publicly.

    Things which should **NOT** go in Website Session: - Large objects. Consider using a separate named Coherence cache for large objects. - Things which could potentially be used by other modules: SessionBindings should be used instead. - Values which won't change after a user signs on: SessionBindings may be a better place for these values. - Product specific values. Currently there is no way to "append" product specific values in to session. Every product would get that value. There are some product specific values in Website Session, but they should be avoided whenever possible.

Answers

  • Donavan Schwartz has pointed out some Website code, that to have a new property in session backed by Coherence, that the following is needed: d:\data\Website\App\Website\SessionState\WebsiteUserSession.cs - Add a line to the end of IPortableObject.ReadExternal & IPortableObject.WriteExternal methods. These need to have a matching index. This is where the value is retrieved and stored in Coherence. - Add a property into the appropriate region that will get/set the value. d:\data\Website\App\Website\SessionState\WebsiteSessionAccessor.cs - Add a get and a set method (follow the pattern from others) that provides access to the value from WebsiteUserSession.