Matthew Dresser
Matthew Dresser

Reputation: 11442

Sitecore API check in code behind if page is being previewed

I have a sublayout in my Sitecore site which is used to perform a redirect via a meta-refresh (a temporary measure) however I'd like editors to be able to preview the page without the redirect happening. Is there a way in the Page_Load method to check, using the Sitecore API, if the page is being previewed?

Upvotes: 3

Views: 1976

Answers (1)

Paul George
Paul George

Reputation: 1817

Yes, check the page mode. Assuming you can move the meta-refresh to a redirect you can do this:

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Sitecore.Context.PageMode.IsPreview)
        {
            // Not in preview mode
            Response.Redirect("redirectionurl.aspx");
        }
    }

Upvotes: 9

Related Questions