Rendering Reason
Determine the context of page rendering
In C1 CMS version 4.2 or later, you can use a public property on
Composite.Core.WebClient.Renderings.Page.PageRenderer.RenderingReason
With this property you can determine what context the current page is rendered in:
namespace Composite.Core.WebClient.Renderings.Page
{
public enum RenderingReason
{
Undefined = 0,
PageView = 1,
C1ConsoleBrowserPageView = 2,
PreviewUnsavedChanges = 4,
ScreenshotGeneration = 8
}
}where:- Undefined: Undefined
- PageView: A page was requested through a browser
- C1ConsoleBrowserPageView: A page is viewed in the CMS Console's browser
- PreviewUnsavedChanges: A page is rendered from within an "Edit page" workflow
- ScreenshotGeneration: A page is rendered to generate an image used for function/template visualization
The property could be useful for function previewing. For example, when previewing a video, a thumbnail with extra video information could be inserted instead of a flash player, or in case of redirecting, you can show the target URL (the following is the Razor syntax):
if(PageRenderer.RenderingReason == RenderingReason.ScreenshotGeneration)
{
@: This function does a redirect to @RedirectUrl
return;
}
Response.Redirect(RedirectUrl);Another example of using the RenderingReason property is optimizing the speed of page previews. Please see "Optimizing Previews" for more information.

