如果正在预览页面,Sitecore API会检入代码

Mat*_*ser 3 c# asp.net sitecore

我的Sitecore站点中有一个子布局,用于通过元刷新(临时措施)执行重定向但是我希望编辑能够在没有重定向的情况下预览页面.是否有一种方法在Page_Load方法中使用Sitecore API检查页面是否正在预览?

Pau*_*rge 9

是的,请检查页面模式.假设您可以将元刷新移动到重定向,您可以执行以下操作:

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