I have an Azure AD B2C token that seems to be correctly returning the currently logged-in user's name. Here is a screenshot from jwt.ms which I am using to decode the token returned by the application after I have logged in:
However, then I attempt to use @User.Identity.Name
in my _Layout.cshtml
. Why is it null? Shouldn't it be equal to the "name" value in the screenshot?
It turned out I was missing the line marked by the comments:
The entire file is located here: https://github.com/Azure-Samples/active-directory-b2c-dotnet-webapp-and-webapi/blob/master/TaskWebApp/App_Start/Startup.Auth.cs
See this working example that is using Owin (which it sounds like you're using).
Source
Source