Client context

From Sense/Net Wiki
Jump to: navigation, search
  • 100%
  • 6.4.1
  • Enterprise
  • Community
  • Planned


Sense/Net ECM stores content in the Content Repository in a huge tree. The parent/child relationships in this tree provide you with a context when a user accesses one of the content through the portal's interface. For example there is the workspace or the site that the content lives in. The accessor user is also part of this context. On the server side this context information is available through the PortalContext class. This article is for client-side developers and portal builders who want to access this context information on the client side.


The client-side context information is a global JSON object that is accessible from any Javascript code and contains the necessary properties for client-side developers to build a rich user interface. You can use these values to display context information or make additional requests to collect more.

Client context values

The object contains the essential properties of the following context items:

  • Current Content
  • Current Site
  • Current Workspace
  • Current List
  • Current Page
  • Current User

If any of the objects above is not available (e.g. because there is no current list there) its value will be null.


This is how a generated client context looks like:

SN.Context = {
  "currentContent": {
    "id": 4095,
    "path": "/Root/Sites/Default_Site/NewsDemo",
    "name": "NewsDemo",
    "displayName": "News Demo"
  "currentSite": {
    "id": 3879,
    "path": "/Root/Sites/Default_Site",
    "name": "Default_Site",
    "displayName": "Default Site"
  "currentWorkspace": {
    "id": 4095,
    "path": "/Root/Sites/Default_Site/NewsDemo",
    "name": "NewsDemo",
    "displayName": "News Demo"
  "currentList": null,
  "currentPage": {
    "id": 4110,
    "path": "/Root/Sites/Default_Site/NewsDemo/(apps)/This/Browse",
    "name": "Browse",
    "displayName": "Browse"
  "currentUser": {
    "id": 1,
    "path": "/Root/IMS/BuiltIn/Portal/Admin",
    "userName": "BuiltIn\\Admin",
    "name": "Admin",
    "domain": "BuiltIn",
    "fullName": "Admin",
    "avatarUrl": "/Root/Sites/Default_Site/demoavatars/Admin.png"

You may access and use its values by the well-known syntax:


Providing the client context

We need to provide the values above for the client (usually a Javascript code running in a browser). Currently this is done by a portlet:

  • Client context portlet

You can put this portlet anywhere onto your page or into a page template. It will generate the context information (based on the current portal context) to the html.

<snpe:ClientContextPortlet runat="server" id="ClientContext" />

In the future we will offer a way to generate a link that will download a separate js file containing the context, instead of generating the values directly into the html.

Server-side API

The generated object is available also on the server side. This may be useful if you want to make these properties accessible in a different way than the portlet above - e.g. returning it as a result of a custom OData action.

The line below will generate the string representation of a JSON object, containing the context information for the current portal context that is globally available.

var text = ClientContext.GenerateScript();

It is also possible to generate a client context for any content. In this case the context information (e.g. workspace, list) will be computed from the provided content instead of the global one.

var text = ClientContext.GenerateScript(content);

Related links


There are no external references for this article.