Kentico CMS 7.0 Developer's Guide

CMSContext class

CMSContext class

Previous topic Next topic Mail us feedback on this topic!  

CMSContext class

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

CMS.CMSHelper.CMSContext class provides useful methods that allow you to access information about the current page, user, etc. All methods are static, which means you can access them directly like CMS.CMSHelper.CMSContext.CurrentAliasPath, without instantiating the CMSContext class.

 

CurrentAliasPath

Alias path of the currently required document.

CurrentDocument

Currently processed document. This object contains all document data including the product data. Please note that retrieving this property is time consuming because it may need to access the database to get the data. You can use the property CurrentPageInfo to get basic document data without additional operations required. It is cached when Content caching is enabled.

CurrentPageInfo

Currently processed page info. This property provides only basic document fields, such as NodeID, NodeName, AliasPath, ClassName, etc. It is cached if Page info caching is enabled.

CurrentSite

Provides information on the current site.

CurrentSiteName

Provides code name of the current site.

CurrentUser

Provides information on the current user and their preferences. Beside the standard UserInfo properties, it also provides the following ones:

 

PreferredCultureCode – gets/sets user’s preferred content culture. You can use this property to change the culture of the displayed content.

 

PreferredUICultureCode – gets/sets user’s preferred UI culture. It’s used mainly by Kentico CMS webparts, controls and in the administration interface.

 

IsAuthorizedPerResource – returns true if the current user is authorized with given permission for given module (resource).

 

IsAuthorizedPerClassName – returns true if the current user is authorized with given permission for the given document type (class name). It checks the global document permissions.

 

IsAuthorizedPerTreeNode – returns true if the current user is authorized with given permission for given document (node).

 

IsPublic – returns true if the current user is the Public user account used for anonymous visitors.

ViewMode

The view mode in which the documents are displayed (edit, design, form, live site, preview).

ResolveCurrentPath

Returns current path or its part according to the provided formatting string. You can use it to get only the first N levels of the path – e.g.:

/{0}/{1}

applied on

“/products/computers/ibm”

results in:

“/products/computers”