Sitecore:在页面编辑器模式下检测用户

Sitecore:在页面编辑器模式下检测用户,sitecore,sitecore7,page-editor,Sitecore,Sitecore7,Page Editor,我可以知道如何使用代码检测处于页面编辑器模式的用户吗? 这是因为,我有一个组件,当用户从页面编辑器浏览时,它将在主索引文件夹而不是web索引文件夹中搜索。请检查:if(Sitecore.Context.PageMode.IsPageEditorEditing) 也正在使用Sitecore 6.6,它不依赖于Sitecore 7 请同时查看Martina Welander提供的此Sitecore 要检查页面是否正常,请使用:if(Sitecore.Context.PageMode.IsNormal

我可以知道如何使用代码检测处于页面编辑器模式的用户吗?
这是因为,我有一个组件,当用户从页面编辑器浏览时,它将在主索引文件夹而不是web索引文件夹中搜索。

请检查:
if(Sitecore.Context.PageMode.IsPageEditorEditing)

也正在使用Sitecore 6.6,它不依赖于Sitecore 7

请同时查看Martina Welander提供的此Sitecore

要检查页面是否正常,请使用:
if(Sitecore.Context.PageMode.IsNormal)

要检查是否为预览模式,请使用:
if(Sitecore.Context.PageMode.IsPreview)

还有其他页面模式:

  • IsPageEditorClassic
  • ispageeditor设计
  • IsPageEditorEditing
  • IsPageEditorNavigating等

如果您感到好奇,可以使用Reflector或dotPeek检查此类:Sitecore.Context.PageMode来自Sitecore.Kernel程序集

我认为您不需要检查页面模式,而只需要使用上下文数据库名称-

var indexName=Sitecore.Context.Database.Name+“_index”;

我使用此语法是为了添加一个用于JS检测的类,相同的代码可以用于带位修改的后端检测:

<html class="@(Sitecore.Context.PageMode.IsPageEditor ? "inexpeditor" : "notexpeditor")">

我倾向于同意。虽然它没有回答最初的问题,但它是解决潜在问题的更好的解决方案。Sitecore 8切换到“Sitecore.Context.PageMode.IsExperienceEditor”。如果您使用的是玻璃,您可以在视图中简写为“@IsInEditingMode”。