It seems this has been asked many times, in many ways, none of which seem to fit my exact situation.
Here's a line from my _LoginPartial.cshtml file:
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" })
See the part that says User.Identity.GetUserName()?
I want to change it to User.Identity.FirstName or User.Identity.GetFirstName().
I don't want it to say "Hello email address", but rather "Hello Bob"
My thought is that I'm simply wanting to show a new property (or method) on the Identity class. Obviously it must be more than that.
I've added the FirstName property and it is available in the AccountController.
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
It does not get exposed in the _LoginPartial file. I want it exposed there!
Thank you for your help
I've done this by adding the First and Last Name to the claim when the user logs in, and then writing my own extension method.
When the user logs in, add the details you want to the set of claims (
AccountController
):The extension method, which just pulls the details from the set of claims for the user:
Now in the partial, just call the new extension method to get the details you want:
EDIT: updated to match more closely the original posters version of the SignInAsync() method
answer updated for Asp .net Core ! Hope this save some time to other users.
}
Even though your answer wasn't "exactly" what I wanted, your comments led me to this solution:
And in my IdentityModel.cs file, I added the two properties FirstName and LastName