<Solved> Member Name
# help-with-umbraco
c
V13 In the provided LoginStatus.cshtml partial there is
<p>Welcome back <strong>@Context?.User?.Identity?.Name</strong></p>
which displays the user's email address. Is there a quick way of getting the member's actual Name or is it a matter of converting the partial to a ViewComponent and firing up the MemberService? Thanks.
Answered my own question. We can now inject stuff into razor pages, so I injected the MemberService and now have everything I need 🙂 I'll leave this here in case anyone else has an early morning panic 🙂
s
Please don't go to the database! 😅
Copy code
csharp
@using Umbraco.Cms.Core.Security
@inject IMemberManager MemberManager;
@{
    var memberName = string.Empty;
    var currentMember = await MemberManager.GetCurrentMemberAsync();
    if (currentMember != null)
    {
        var member = MemberManager.AsPublishedMember(currentMember);
        memberName = member?.Name;
    }
}

<p>@memberName</p>
d
I may be mistaken, but I thought that
IMemberManager.GetCurrentMemberAsync
also touched the database through dotnet identity. You should probably measure it to see if you get database bottlenecks.
s
I haven't looked into that. Just saying that using any of the
Services
will cause heavy database operations and you should only use them if you're going to need to do updates, not for querying.
d
yeah, totally agree
2 Views