Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSS and Category Pages are giving 404 as in the site I used IContentLastChanceFinder #446

Closed
RPanc opened this issue Mar 5, 2024 · 4 comments

Comments

@RPanc
Copy link

RPanc commented Mar 5, 2024

Hi all

 public class My404ContentFinder : IContentLastChanceFinder
    {
        private readonly IDomainService _domainService;
        private readonly IUmbracoContextAccessor _umbracoContextAccessor;

        public My404ContentFinder(IDomainService domainService, IUmbracoContextAccessor umbracoContextAccessor)
        {
            _domainService = domainService;
            _umbracoContextAccessor = umbracoContextAccessor;
        }

        public Task<bool> TryFindContent(IPublishedRequestBuilder contentRequest)
        {
            // Find the root node with a matching domain to the incoming request
            var allDomains = _domainService.GetAll(true).ToList();
            //var domain = allDomains?
            //    .FirstOrDefault(f => f.DomainName == contentRequest.Uri.Authority
            //                         || f.DomainName == $"https://{contentRequest.Uri.Authority}"
            //                         || f.DomainName == $"http://{contentRequest.Uri.Authority}");
            var domain = allDomains.Where(f => f.DomainName == contentRequest.Uri.Authority
              || f.DomainName == $"https://{contentRequest.Uri.Authority}"
              || f.DomainName == $"http://{contentRequest.Uri.Authority}").FirstOrDefault();

            var siteId = domain != null ? domain.RootContentId : allDomains.Any() ? allDomains.FirstOrDefault()?.RootContentId : null;

            if (!_umbracoContextAccessor.TryGetUmbracoContext(out var umbracoContext))
            {
                return Task.FromResult(false);
            }

            if (umbracoContext.Content == null)
                return new Task<bool>(() => contentRequest.PublishedContent is not null);

            var siteRoot = umbracoContext.Content.GetById(false, siteId ?? -1);

            if (siteRoot is null)
            {
                return Task.FromResult(false);
            }

            // Assuming the 404 page is in the root of the language site with alias fourOhFourPageAlias
            var notFoundNode = siteRoot.Children?.FirstOrDefault(f => f.ContentType.Alias == "404");

            if (notFoundNode is not null)
            {
                contentRequest.SetPublishedContent(notFoundNode);
            }

            // Return true or false depending on whether our custom 404 page was found
            return Task.FromResult(contentRequest.PublishedContent is not null);
        }
    }

builder.SetContentLastChanceFinder();
I wrote a content finder like above but for the RSS & categories pages are always going to 404.

@Shazwazza
Copy link
Owner

I understand there is some fundamental routing conflicts going on with Articulate and Umbraco (and potentially other Umbraco Cloud things) which needs to be resolved in the correct way. Using last chance content finders is only a work around and not a viable long term solution.

Unfortunately, I won't have time to help debug this until april since I am away until the end of the month.

@gavinfaux
Copy link
Contributor

@RPanc As a workaround, exclude the Articulate custom routes from your finder, reference this thread.

Note that example routes to filter are not exact, it's still possible to get 404's on some of these routes if wrong node id/data passed, in which case the default Umbraco not found page is served - you can customise/override this with your own template placed in \umbraco\UmbracoWebsite\NotFound.cshtml

You will likely need to build Articulate from latest sources to pick up latest commits that fix or work-around other routing concerns (review commit history/latest PR's to check if these effect you).

@Shazwazza
Copy link
Owner

Please try the latest Articulate release 5.0.3 and let me know if the problem is resolved.

@Shazwazza
Copy link
Owner

I can replicate the issue. For now there is a workaround in the other issue. The underlying problem and how to fix is very strange, I'll actually need to debug this with the Umbraco source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants