CMSContext class

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 dabatase 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 his/her preferences. Beside the standard UserInfo properties, it also provides the following ones:

 

MenuItemViewMode the view mode used for page (menu item) documents (cms.menuitem type).

 

PreferredUICultureInfo read-only property returning the current users preferred UI culture (as CultureInfo object).

 

PreferredCultureCode gets/sets users preferred content culture. You can use this property to change the culture of the displayed content.

 

PreferredUICultureCode gets/sets users preferred UI culture. Its 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).

WebApplicationVirtualPath

Returns the virtual path of the current web application.

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”