Copied to clipboard

Flag this post as spam?

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


  • Isioma Nnodum 1 post 71 karma points
    Nov 01, 2023 @ 15:39
    Isioma Nnodum
    0

    Member Roles collection is empty until GetRolesAsync is called.

    The expected result after running this code is that the member.Roles collection will be populated with the member's roles.

    var member = await MemberManager.GetCurrentMemberAsync();
    var userData = new
    {
        member.Id,
        member.Email,
        member.Name,
        Roles = member.Roles.Select(x => x.RoleId).ToArray()
    };
    

    However, when stepping through the code the member.Roles collection is empty.

    enter image description here

    Changing the code to fetch the roles by calling MemberManager.GetRolesAsync(member) directly does return the expected collection.

    var member = await MemberManager.GetCurrentMemberAsync();
    var roles = await MemberManager.GetRolesAsync(member);
    var userData = new
    {
        member.Id,
        member.Email,
        member.Name,
        Roles = roles.ToArray()
    };
    

    However, when stepping through the code I see that now the member.Roles collection is populated.

    enter image description here

    It's not clear if this is the intended usage or a bug.

    Some more contextual information:

    • This logic is a snippet from a method defined in an abstract class that extends Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    • Views that implement the abstract class (using the @inherits directive) will call this method as any other helper method in a Razor page.
    • The IMemberManager instance is being resolved by calling Context.RequestServices.GetRequiredService<IMemberManager>()
Please Sign in or register to post replies

Write your reply to:

Draft