Table of Contents

Interface ICmsContext

Namespace
ToSic.Sxc.Context
Assembly
ToSic.Sxc.dll

This is the runtime context of your code in the CMS. It can tell you about the site, page, module etc. that you're on. Note that it it Platform Agnostic so it's the same on Dnn, Oqtane etc.

🪒 In Dynamic Razor it's found on CmsContext
🪒 In Typed Razor it's found on MyContext, but many objects are directly available, like MyPage

CMS Context in your Code

All your Razor and WebApi code will have a property CmsContext which provides you information about the environment you're running in.

Here's a Code Snippet for Razor, showing you what page etc. your code is running on:


ModuleId: @CmsContext.Module.Id

History

  • Added in 2sxc 11.11
[PublicApi]
public interface ICmsContext

Properties

Block

Information about the current block, similar to the module but a bit different.

ICmsBlock Block { get; }

Property Value

ICmsBlock

Remarks

Added ca. v13, but not documented/published till v17.

Culture

Information about languages / culture of the current request

ICmsCulture Culture { get; }

Property Value

ICmsCulture

Module

Information about the Module / Container which holds a 2sxc content block in the CMS

ICmsModule Module { get; }

Property Value

ICmsModule

Page

Information about the current Page (called Tab in DNN). It's especially useful to get current URL Parameters.

ICmsPage Page { get; }

Property Value

ICmsPage

Platform

Information about the platform that's currently running.

ICmsPlatform Platform { get; }

Property Value

ICmsPlatform

Site

Information about the Site (called Portal in DNN)

ICmsSite Site { get; }

Property Value

ICmsSite

User

Information about the current user. It's especially useful to see if the user has any kind of Admin privileges.

ICmsUser User { get; }

Property Value

ICmsUser

View

View-information such as the view Name, Identity or Edition.

ICmsView View { get; }

Property Value

ICmsView

Remarks

New in v12.02