How to display current logged in user name without any server call in master page?
-
01-01-2021 - |
Question
We have a custom master page and intend to show current logged in username. I can find quite a few solutions but they require server call either with REST API or CSOM.
Is there a way to show the currently logged in user name in master page without any server call?
La solution
In order to display stuff without querying the server, you will have to use objects that are already available in the context of the page.
you have for example the user id, but not the user full name. perhaps there are other objects you can look for.
ctx.CurrentUserId
an alternative is of course looking inside the DOM, as you already have the user menu on the top right with the user's name in there
e.g.
$(".ms-welcome-root a").contents().get(0).nodeValue
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange