[英]How to return Umbraco 404 page when no content found in UmbracoVirtualNodeRouteHandler
我正在使用UmbracoVirtualNodeRouteHandler
來使用一些自定義邏輯來查找我的Umbraco內容。 效果很好,除了找不到內容時。 當我找不到內容時,我想顯示Umbraco 404頁面 。
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
{
var content = findMyContent();
//attempt 1
return content; //even if content is null
//end attempt 1
//attempt 2
if(content == null)
{
throw new HttpException(404, "Blogpost not found");
}
return content;
//end attempt 2
}
嘗試1會導致默認的未樣式化404頁面顯示
“您正在尋找的資源已被刪除,名稱已更改或暫時不可用。”
我找不到內容時如何顯示自定義的Umbraco 404頁面?
您是否嘗試使用umbracoSettings.config
的配置?
您可以通過引用節點ID,GUID或XPATH為404頁配置自定義節點:
<errors>
<error404>1234</error404>
</errors>
<!--
The value for error pages can be:
* A content item's integer ID (example: 1234)
* A content item's GUID ID (example: 26C1D84F-C900-4D53-B167-E25CC489DAC8)
* An XPath statement (example: //errorPages[@nodeName='My cool error']
-->
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.