【问题标题】:Sitecore Habitat how can I create a basic 404 page?Sitecore Habitat 如何创建基本的 404 页面?
【发布时间】:2016-12-14 08:47:06
【问题描述】:

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

我的 网站 项目中有以下内容。 <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/页面时收到以下错误/堆栈跟踪,查看控制台中的网络选项卡是 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 sitecore8 sitecore-mvc


    【解决方案1】:

    这些设置不应指向 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/)。我自己还没有使用它,但它应该可以满足您的需求。

    【讨论】:

    • 我们决定改用一个包,可能不是同一个包,但我认为这是最简单且可能不太受挫的路径。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    相关资源
    最近更新 更多