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

时间:2016-08-08 14:12:43

标签: sitecore sitecore8 sitecore-mvc

我正在尝试在Sitecore Habitat中创建一个基本的404页面,完全难倒并且是Sitecore的新手。我使用基本页面在内容树中创建了此NotFound页面。

我的 网站 项目中包含以下内容。 <projectName>.web.config文件夹下的app_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

1 个答案:

答案 0 :(得分:0)

这些设置不应指向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/)。我自己还没有使用它,但它应该做你想要的。