I have created a custom 404 handler which has been working fine up to now (for the past 2 months). It allows the content editor to create a content page within Umbraco and then select that page to be used as the 404 page.
All of a sudden we are getting intermittent 404 errors on a few pages in the site. When I look at PublishedContentRequest, PublishedContent is null. If I reload the site then it seems to be able to find the content without issues.
My code is as follows:
public class PageNotFound : IContentFinder { public bool TryFindContent(PublishedContentRequest contentRequest) { if (contentRequest.PublishedContent == null) { var url = contentRequest.Uri.GetAbsolutePathDecoded();
var website = UmbracoContext.Current.ContentCache.GetById(contentRequest.Domain.RootNodeId);
if (website != null) { var page = website.GetProperty("PageNotFoundErrorPage") != null ? website.GetProperty("PageNotFoundErrorPage").Value.ToString() : "1"; int errorPageId; int.TryParse(page, out errorPageId);
Error with Custom 404 Handler in Umbraco 7.1.8
I have created a custom 404 handler which has been working fine up to now (for the past 2 months). It allows the content editor to create a content page within Umbraco and then select that page to be used as the 404 page.
All of a sudden we are getting intermittent 404 errors on a few pages in the site. When I look at PublishedContentRequest, PublishedContent is null. If I reload the site then it seems to be able to find the content without issues.
My code is as follows:
public class PageNotFound : IContentFinder
{
public bool TryFindContent(PublishedContentRequest contentRequest)
{
if (contentRequest.PublishedContent == null)
{
var url = contentRequest.Uri.GetAbsolutePathDecoded();
var message = "Page not found: " + url;
LogHelper.Warn(MethodBase.GetCurrentMethod().DeclaringType, message);
contentRequest.SetResponseStatus(404, "Not Found");
var website = UmbracoContext.Current.ContentCache.GetById(contentRequest.Domain.RootNodeId);
if (website != null)
{
var page = website.GetProperty("PageNotFoundErrorPage") != null ? website.GetProperty("PageNotFoundErrorPage").Value.ToString() : "1";
int errorPageId;
int.TryParse(page, out errorPageId);
contentRequest.PublishedContent = UmbracoContext.Current.ContentCache.GetById(errorPageId);
}
}
return contentRequest.PublishedContent != null;
}
}
I can't understand why the published content is null. It's an intermittent issue so not related to site reload etc.
is working on a reply...