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.
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.
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>()
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.However, when stepping through the code the
member.Roles
collection is empty.Changing the code to fetch the roles by calling
MemberManager.GetRolesAsync(member)
directly does return the expected collection.However, when stepping through the code I see that now the
member.Roles
collection is populated.It's not clear if this is the intended usage or a bug.
Some more contextual information:
Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inherits
directive) will call this method as any other helper method in a Razor page.IMemberManager
instance is being resolved by callingContext.RequestServices.GetRequiredService<IMemberManager>()
is working on a reply...