【发布时间】:2016-10-26 12:08:25
【问题描述】:
我当前的代码如下。
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
我想在 ApplicationUser 类中添加更多属性,以便这些字段在视图中可用,例如
@User.Identity.FullName
我的登录操作位于here
【问题讨论】:
-
您无法扩展该类,但您可以获得
ApplicationUser的实例(您可以在其中添加自己的属性)。对于像这样的简单身份验证:UserManager.FindById(User.Identity.GetUserId()); -
也许this 会有所帮助
-
@AdrianoRepetti 请查看stackoverflow.com/questions/28335353/…
-
@BharatPatidar 是的,您可以使用声明来做,但如果引入它们的唯一原因是添加属性,则 IMo...
标签: c# asp.net asp.net-mvc-5 asp.net-identity