我正在使用MVC5,创建了一个带有自定义属性的“ApplicationUser:IdentityUser”。现在我想要在layout.cshtml中获取一个自定义属性(Avatar),以便在不同布局(标题,侧边栏)视图中显示已登录用户的图像。我该怎么做?
public class ApplicationUser : IdentityUser
{
public string Avatar { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
}
目前我正在使用@User.Identity.Name
在我的视图中获取已登录用户的名称。我还想要用户的头像。
我该如何获取它呢?