Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Muhammad Kaleem 4 posts 73 karma points
    Oct 04, 2021 @ 15:43
    Muhammad Kaleem
    0

    Url rewriting issue: "This document is published but its URL cannot be routed"

    Hi, umbraco experts, i am writing following code for the purpose of url rewriting in umbraco cms 8.13.1, while publish specific content now i am getting "This document is published but its URL cannot be routed" and unable to browse content page with new url, i have already implemented contentfinder as well, please check following sample code and suggest any solution, your support will be highly appreciated!

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]

    public class ContentFinderComposer : IUserComposer

    {

    public void Compose(Composition composition)

    {

    composition.ContentFinders().InsertBefore

    }

    }

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]

    public class UrlComposer : IComposer

    {

    public void Compose(Composition composition)

    {

    composition.UrlProviders().Insert

    }

    }

    public class TestUrlHelper : DefaultUrlProvider

    {

    public TestUrlHelper ( IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper ) : base(requestSettings, logger, globalSettings, siteDomainHelper) { }

        public override UrlInfo GetUrl( UmbracoContext umbracoContext,  IPublishedContent content,  UrlMode mode,  string culture,  Uri current)
        {
            UrlInfo defaultUrlInfo = base.GetUrl(umbracoContext, content, mode, culture, current);
            // If we've got a node and matches the doctype we're after
            if (content != null && content.ContentType.Alias == "news")
            {
                if (!defaultUrlInfo.IsUrl)
                {
                    //this is a message (eg published but not visible because the parent is unpublished or similar)
                    return defaultUrlInfo;
                }
                else
                {
                    //manipulate the url somehow in a custom fashion:
                    var originalUrl = defaultUrlInfo.Text;
                    var customUrl = "/customurl" + originalUrl;
                    return new UrlInfo(customUrl, true, defaultUrlInfo.Culture);
                }
    
            }
            else
            {
                var originalUrl = defaultUrlInfo.Text;
                return new UrlInfo(originalUrl, true, defaultUrlInfo.Culture);
            }
        }
    
        // Make a reference to the other default function
        public override IEnumerable<UrlInfo> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
        {
            return base.GetOtherUrls(umbracoContext, id, current);
        }
    }
    public class PublishEventComponent : IComponent
    {
        public void Initialize()
        {
            ContentService.Published += ContentService_Published;
        }
        public void Terminate()
        {
    
        }
        private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e)
        {
            foreach (IContent node in e.PublishedEntities)
            {
                // Set blog post `umbracoUrlAlias`
                if (node.ContentType.Alias == "news")
                {
    
                }
            }
        }
    
    }
    
    public class BlogContentFinder : IContentFinder
    {
        public bool TryFindContent(PublishedRequest contentRequest)
        {
            string path = contentRequest.Uri.GetAbsolutePathDecoded();
    
            if (path.StartsWith("/news/"))
            {
                var content = contentRequest.UmbracoContext.Content.GetById(contentRequest.Domain.ContentId);
                contentRequest.PublishedContent = content;
                return true;
            }
            return false;
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft