I've added a few new columns to User model which inherited from IdentityUser:
public class ApplicationUser : IdentityUser
{
public int Age { get; set; }
public bool Sex { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
ClaimsIdentity userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
//userIdentity.AddClaim(new Claim("age", this.Age.ToString()));
return userIdentity;
}
}
By default I can only get user name, like shown in _LoginPartial.cshtml:
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
I'd like get custom info from User.Identity like Age and Sex, for example. I find the solutions around pretty weird to implement and using claim I couldn't make it global once I'm gonna display it in every page.
If the way to do it is by adding claims like this:
userIdentity.AddClaim(new Claim("age", this.Age.ToString()));
How can I get it easily in a View?