Copied to clipboard

Flag this post as spam?

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


  • Sebastian Felis 9 posts 127 karma points
    Jan 04, 2022 @ 21:49
    Sebastian Felis
    0

    How to get Member by Udi in Umbraco 9

    Hello,

    I migrate my project to Umbraco 9 and I need to get a Content, Member and Media by Udi. In Umbraco 8 the UmbracoHelper contains the method PublishedContent which do this exactly. In new Umbraco version access to members is moved to IMemberManager. IMemberManager contains also a method to convert the MemberIdentityUser object (which is returned by methods inside IMemberManager) to IPublisehdContent. However I don't how to get MemberIdentityUser object by Udi.

    So how to get a Member by Udi?

  • Rune Grønkjær 1372 posts 3103 karma points
    Jan 27, 2022 @ 11:12
    Rune Grønkjær
    0

    Did you find a solution?

    /Rune

  • Sebastian Felis 9 posts 127 karma points
    Jan 27, 2022 @ 19:22
    Sebastian Felis
    101

    The best solution what I have been finding is using IIdKeyMap service. You need to inject IIdKeyMap to your class and use it some like that:

    IPublishedContent publishedContent = null;
    var memberAttempt = _idKeyMap.GetIdForUdi(nodeUdi);
    if (memberAttempt.Success)
    {
       var memberId = memberAttempt.Result;
       var member = await _memberManager.FindByIdAsync(memberId.ToString());
       if (member != null)
       {
             publishedContent = _memberManager.AsPublishedMember(member);
       }
    }
    
  • Rune Grønkjær 1372 posts 3103 karma points
    Jan 28, 2022 @ 06:00
    Rune Grønkjær
    0

    Thanks Sebastian,

    Weird that it's so awkward working with members. Must be because they are so integrated with the native .net member system.

    I will see if your solution is useable in my situation 👍

    /Rune

  • 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