Copied to clipboard

Flag this post as spam?

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


  • Rik Hodiamont 56 posts 156 karma points
    Jan 30, 2015 @ 12:13
    Rik Hodiamont
    0

    API + umbraco URL

    Hi!

    I use the api (contentservice) of Umbraco 7. How can I get the nice URL of the item I selected with the api? I can get the nodeID and link with the nodeID to the page, but I want nice seo-friendly url's if that's possible.

    Thanks in advance for your help.

    Kind regards, Rik

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 30, 2015 @ 12:29
    Dan Lister
    0

    Hi Rik,

    Something like the following should do the trick:

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    
    var contentItem = ApplicationContext.Current.Services.ContentService.GetById(1234);
    var contentItemUrl = umbracoHelper.NiceUrl(contentItem.Id);
    

    Hope that helps.

    Thanks, Dan.

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 30, 2015 @ 12:31
    Dan Lister
    100

    Or if you are doing this within a view/template, you could use the following:

    var contentItem = ApplicationContext.Current.Services.ContentService.GetById(1234);
    var contentItemUrl = Umbraco.NiceUrl(contentItem.Id);
    

    Thanks, Dan.

  • Rik Hodiamont 56 posts 156 karma points
    Jan 30, 2015 @ 14:32
    Rik Hodiamont
    0

    Thank you Dan. Your solution works!

Please Sign in or register to post replies

Write your reply to:

Draft