Copied to clipboard

Flag this post as spam?

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


  • Maciej Rakowski 11 posts 91 karma points
    May 26, 2017 @ 16:08
    Maciej Rakowski
    0

    Umbraco cloud and guid vs nodeid also how to redirect to page with guid

    Hi,

    So we deployed our umbraco website to cloud and moved all the data there using Umbraco Deploy just to find out that nodeIds are being changed when transfered. That causes some pain for us. We managed to search for content by calling UmbracoHelper.TypedContend(Guid) but we need to do something similar with redirects as our current code

    RedirectToUmbracoPage(1334)
    

    stopped working, because ids are different. As I can see the guids are the same on both ends.

    So my question is - is there a way to redirect to umbraco page via Guid. If not what's the best solution for that?

    Thanks Maciej

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Jun 13, 2017 @ 06:17
    Søren Kottal
    1

    Hi Maciej

    Are you hardcoding your id's?

    Maybe you can fetch the id like this:

    var pageToRedirect = Umbraco.TypedContentSingleAtXPath("//[@key='ce0e90fc-866d-4b71-9c9d-f8be1c36fc83']");
    RedirectToUmbracoPage(pageToRedirect.Id);
    

    But are you sure you want to bind to either id or guid in that way?

    Maybe you can come up with something smarter, like a content picker on a settings node, or an xpath to find the correct page. Someday one of your editors will delete that page, and then you have to update your code with a new guid.

  • Maciej Rakowski 11 posts 91 karma points
    Jun 14, 2017 @ 15:01
    Maciej Rakowski
    0

    Hi Søren,

    Yes, we are hardcoding Guids for some pages that needs to be called from backend code. I've ended with something like this in the end:

     var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
     var page = umbracoHelper.TypedContent(guid);
    
     return page.Id;
    

    And as per second - I'm not afraid about the editors deleting the page. That's the general risk I think - if they aren't careful enough and delete the node that's marked by devs as DoNotDelete then I have no faith it will be recreated the way I want it.

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Jun 14, 2017 @ 18:51
    Søren Kottal
    1

    Ooh, didn't know you could put guids into .TypedContent() :)

    Always a risk having editors, my advice was just so you wouldn't need a rebuild in case of deletions :)

Please Sign in or register to post replies

Write your reply to:

Draft