Kentico Tip: How to Remove the Preview Mode
Posted by Dave Conder on May 25, 2016
It's always important to preview content changes before they are published, and Kentico easily provides the ability to do so. While this is a great feature, it also creates an unwanted side effect when you’re working in the Pages application.
Today, I'll explain the best ways to work around this issue.
The Quick Fix
When previewing content pages prior to publishing, if you navigate to the page tab on any page, and then (in the same browser session) visit a live page, you’ll see the following bar at the top:
When you see this, some functionality in templates and web parts may not work properly, so you must close the preview mode before you continue. Easy enough. But because this setting is cookie-based, it will persist each time you reload the Page tab in that browser. This can become annoying when you have a large number of changes in a row that you'd like to preview.
A simple trick to avoid continuously closing preview mode is to implement private browsing mode for your testing window, or better yet, try two different browsers for development and testing.
A Permanent Solution
If you are not using preview mode on your site, another option you have is to simply disable it. If you want to disable preview mode completely, you can do so by adding the following code to PortalTemplate.aspx:
protected override void OnPreInit(EventArgs e)
// If Preview mode (Cookie CMSViewMode == 3), set to Live Site (Cookie CMSViewMode == 0)
if (PortalContext.ViewMode == CMS.PortalEngine.ViewModeEnum.Preview)
PortalContext.ViewMode = CMS.PortalEngine.ViewModeEnum.LiveSite;
You can also put this code directly in a web part, but note that due to the page event lifecycle, it may not work on the first page load because the web part’s PreInit event is called after PortalTemplate’s. Additionally, you may want to add some conditional logic as well, such as checking if the current user is a Global Administrator.
We hope this is a helpful tip! In general, we try to avoid modifying any core Kentico code, but sometimes we do have to make changes to PortalTemplate.aspx in order to add body tags or other custom markup. While it’s not always ideal to do so, it’s nice to know that the option exists if needed.
Have any Kentico-related quandaries you need assistance with? Just ask! Our BlueModus team has been working with the platform for over a decade and would be happy to help.
Dave Conder has been using technology to create value and solve problems for more than 15 years. His background includes technical management, network architecture and design, security, and application development. As CTO, Dave ensures that BlueModus always uses the best people, practices, and tools to deliver world-class digital marketing solutions.