Sitecore Habitat 如何创建基本的 404 页面?

Sitecore Habitat how can I create a basic 404 page?

我正在尝试在 Sitecore Habitat 中创建一个基本的 404 页面,这对 Sitecore 来说完全是个新问题。我使用基本页面在内容树中创建了这个 NotFound 页面。

我的 Website 项目中有以下内容。 <projectName>.web.configapp_config > include > project 文件夹下。

<settings>
  <setting name="Preview.DefaultSite" value="qube" />
    <!--  ITEM NOT FOUND HANDLER
        Url of page handling 'Item not found' errors
  -->
  <setting name="ItemNotFoundUrl">
    <patch:attribute name="value">/NotFound</patch:attribute>
  </setting>
    <!--  LINK ITEM NOT FOUND HANDLER
        Url of page handling 'Link item not found' errors
  -->
    <setting name="LinkItemNotFoundUrl">
      <patch:attribute name="value">/NotFound</patch:attribute>
    </setting>
    <!--  LAYOUT NOT FOUND HANDLER
        Url of page handling 'Layout not found' errors
  -->
    <setting name="LayoutNotFoundUrl">
      <patch:attribute name="value">/NotFound</patch:attribute>
    </setting>
    <!--  ERROR HANDLER
        Url of page handling generic errors
  -->
    <setting name="ErrorPage">
      <patch:attribute name="value">/NotFound</patch:attribute>
    </setting>
</settings>

我在尝试访问不存在的 URL/page 时收到以下 error/stack 跟踪,查看控制台中的网络选项卡是 HTTP 500 server error 而不是 404我想要:

[HttpException (0x80004005): Error executing child request for /NotFound.]
   System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2292
   System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm) +822
   System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm) +76
   System.Web.HttpServerUtility.Transfer(String path) +45
   Sitecore.Pipelines.HttpRequest.ExecuteRequest.HandleItemNotFound(HttpRequestArgs args) +845
   (Object , Object[] ) +74
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +484
   Sitecore.Nexus.Web.HttpModule.(Object , EventArgs ) +525
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +142
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +92

这些设置不应指向 Sitecore 路径。如果你想使用一个项目作为 404 页面,你应该创建一个处理器来添加到 httpRequestBegin 管道。更多信息和代码以及该主题可以在多个博客中轻松找到,例如https://briancaos.wordpress.com/2013/03/21/sitecore-404-without-302/

或者您可以使用 Sitecore 错误管理器模块(参见 https://ctor.io/handling-404-and-other-errors-with-sitecore-items/)。我自己还没有使用它,但它应该做你想要的。