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 required document. Please note: this method results in a query into the database. If you need only basic document data, you can use the CurrentPageInfo property that is cached (if caching is used).

CurrentPageInfo

Currently required document (page). This method provides only common document fields, such as NodeID, NodeName, AliasPath, ClassName, etc. Its cached (if caching is used).

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:

 

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

 

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.

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”