Return to doc.sitecore.com

Valid for Sitecore 5.3
How would I detect if a page is being viewed in preview mode from the API?

Q:

I need to add some extra display information when my client is viewing a page in preview mode. How would I detect if a page is being viewed in preview mode from the API?

A:

You can analyze the Sitecore.Context.Site.DisplayMode property. It is equal to the Sitecore.Sites.DisplayMode.Edit value in the webedit mode, Sitecore.Sites.DisplayMode.Preview value in the preview mode and Sitecore.Sites.DisplayMode.Normal in the normal mode.