[英]How to return Umbraco 404 page when no content found in UmbracoVirtualNodeRouteHandler
I'm using UmbracoVirtualNodeRouteHandler
to do use some custom logic to find my Umbraco Content. 我正在使用
UmbracoVirtualNodeRouteHandler
来使用一些自定义逻辑来查找我的Umbraco内容。 This works great except for when I don't find the content. 效果很好,除了找不到内容时。 When I don't find content, I want to show the Umbraco 404 page .
当我找不到内容时,我想显示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
}
Attempt 1 results in the default unstyled 404 page saying 尝试1会导致默认的未样式化404页面显示
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." “您正在寻找的资源已被删除,名称已更改或暂时不可用。”
Attempt 2 results in showing my custom error 500 page. 尝试2会显示我的自定义错误500页面。
How do I show my custom Umbraco 404 page when I don't find content? 我找不到内容时如何显示自定义的Umbraco 404页面?
Did you try to use the configuration in umbracoSettings.config
? 您是否尝试使用
umbracoSettings.config
的配置?
You can configure a custom node for the 404 page by referencing the node ID, GUID or XPATH: 您可以通过引用节点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.