我在Asp.net mvc上有点新手,在我的项目中,我将有一个用户注册,一个编辑用户配置文件和查看用户配置文件(创建,编辑,详细信息)的可能性,有没有一种方法,我可以添加新的属性到用户表,以便我可以脚手架用户?在那一刻,我只是这样做的:
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;
}
[Required]
public string Nome { get; set; }
public string Telemóvel { get; set; }
public int Idade { get; set; }
public string Sobre { get; set; }
}我需要扩展用户身份才能做我想做的事吗?我该怎么做呢?
发布于 2016-05-15 17:39:18
搭建通常是通过ViewModels完成的,而不是在模型类上。要实现此目的,请使您的身份用户具有(如有必要,可自定义属性),添加迁移并创建一个单独的ViewModel类,该类具有注册新用户所需的自定义属性,并在post操作中将映射到身份用户。
https://stackoverflow.com/questions/37236465
复制相似问题