How To Check if an Episerver Page is Being Rendered in Edit Mode or Preview Mode

There are a number of situations where you may need to display information differently; when a page is being rendered in the editor, or, previewed. you may want to display different classes, or, even hide or show whole sections of code to allow content editors to have access to some additional back-end only features.  In Episerver we have three modes available to us:

  • Default - Normal web view
  • Edit - In the editor
  • Preview
If we want to know if we're in preview mode we can use the 'CurrentContextMode'
In the real world, I've only ever done things differently in edit mode.  For this reason I'd recommend you use the PageEditing class rather than the 'CurrentContextMode'.
    var inEditMode = PageEditing.PageIsInEditMode;
If the page is in edit mode, then it will be true. If you additionally want to get the editor Url for any page, you can use the GetEditUrl() method like:
    var pagesEditorUrl = PageEditing.GetEditUrl(new ContentReference(3));

submit to reddit

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top