【问题标题】:Sitecore pipeline processor messing up the CMSSitecore 管道处理器弄乱了 CMS
【发布时间】:2023-06-09 00:38:01
【问题描述】:

我有一个流水线处理器,它在网站上按预期工作,但在您进入 CMS 时会造成严重破坏。

确定请求是否发往 CMS 的正确方法是什么? 最好我想要一些比检查 URL 是否包含“/sitecore/”更强大的东西。

【问题讨论】:

    标签: sitecore pipeline processor


    【解决方案1】:

    站点上下文是执行此操作的好方法。您可以使用标准的 Sitecore 配置工厂方法来输入应该使用该扩展的站点名称,然后忽略其他名称,包括“shell”。

    参考https://community.sitecore.net/technical_blogs/b/sitecorejohn_blog/posts/the-sitecore-asp-net-cms-configuration-factory

    【讨论】:

      【解决方案2】:

      如果您在“shell”站点中,您可以优雅地退出...

      if (Sitecore.Context.Site.Name.Equals("shell", StringComparison.InvariantCultureIgnoreCase))
      {
          // Exit here if we're avoiding the sitecore shell altogether
          return;
      }
      

      这取决于导致代码崩溃的情况。您可以检查页面模式以避免出现问题模式...

      if (Sitecore.Context.PageMode.IsPageEditorEditing)
      {
          // Exit here if we're avoiding someone editing the page.
          return;
      }
      

      【讨论】:

      • 谢谢。这是一个很好的答案。显然是识别上下文站点是否为“Shell”的关键。老实说,我没有意识到 CMS 是作为这个站点运行的。
      • 我选择上一个答案作为接受的答案,因为它更易于配置,但两者都非常适合我的目的。