Copied to clipboard

Flag this post as spam?

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


  • keilo 563 posts 1018 karma points
    Jan 02, 2016 @ 12:25
    keilo
    0

    Retrieving list of Custom URL entries from Code

    First of all wishing You a happy new year and thanking you for maintaining this great package.

    I have created a static cache of the umbraco site which uses 301 url tracker.

    On the static copy of the site, I would like to create the pseudo (redirect) pages for the Custom URL entries that users have created with 301 url tracker.

    My question is how can I go about retrieving the list of Custom URL entries created within 301 url tracker, within code (Razor/Event-API)?

    Would greatly appreciate if you can share your thoughts.

  • Stefan Kip 1606 posts 4098 karma points c-trib
    Jan 04, 2016 @ 10:22
    Stefan Kip
    100

    You can use InfoCaster.Umbraco.UrlTracker.Repositories.GetUrlTrackerEntries(int? maximumRows, int? startRowIndex, string sortExpression = "", bool _404 = false, bool include410Gone = false, bool showAutoEntries = true, bool showCustomEntries = true, bool showRegexEntries = true, string keyword = "", bool onlyForcedRedirects = false)

    Just leave showCustomEntries set to true and the other arguments according to your needs.

  • keilo 563 posts 1018 karma points
    Jan 04, 2016 @ 12:10
    keilo
    0

    Thanks for the pointer.

    I realised one needs to add UrlTrackerRepository after Repositories (looking at other threads, no access to VS)

    So this is what I come up with to get all the (only) Custom URLs in Razor: Not sure if its complete... hopefully will help others looking for the same.

    var x =  InfoCaster.Umbraco.UrlTracker.Repositories.UrlTrackerRepository.GetUrlTrackerEntries(100, 1, "", false, false, false, true, false, "", false);
    
    foreach (var entry in x ){
    
        <p>Entry with id  @entry.Id</ p >
        <p>OldUrl: @entry.OldUrl</p>
        <p>RedirectUrl: @entry.RedirectUrl</p>
        <p>CalculatedOldUrl:@entry.CalculatedOldUrl</p>
        <p>CalculatedRedirectUrl: @entry.CalculatedRedirectUrl</p>
        <hr/>
    }
    
  • Stefan Kip 1606 posts 4098 karma points c-trib
    Jan 04, 2016 @ 12:48
    Stefan Kip
    1

    Ah I'm sorry, forgot to include the class name indeed. AFAIK you don't need to set maximumRows and startRowIndex, so you'll get:

    var x = InfoCaster.Umbraco.UrlTracker.Repositories.UrlTrackerRepository.GetUrlTrackerEntries(null, null, "", false, false, false, true, false, "", false);

  • keilo 563 posts 1018 karma points
    Jan 04, 2016 @ 14:19
    keilo
    0

    Many thanks for clarifying!

    changed the first and 2nd param to null to get all.

    For Custom Urls concerned, is it safe to assume the attribs to read, to replicate the manual redirect, are the following fields?

    <p>CalculatedOldUrl:@entry.CalculatedOldUrl</p>
    <p>CalculatedRedirectUrl: @entry.CalculatedRedirectUrl</p>
    
  • Stefan Kip 1606 posts 4098 karma points c-trib
    Jan 04, 2016 @ 14:20
    Stefan Kip
    1

    Yeah I think so :-)

  • keilo 563 posts 1018 karma points
    Jan 04, 2016 @ 14:21
    keilo
    0

    Cool! Many thanks again!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies