【发布时间】:2015-06-13 01:24:56
【问题描述】:
是否可以为不同的角色提供不同的个人资料?还是我必须:
- 创建包含所有共享字段的配置文件,即名字、姓氏。
- 创建两个单独的表,每个表都包含自己独特的属性,即表 1:DOB 表 2:地址和指向配置文件的链接?
【问题讨论】:
标签: c# asp.net roles asp.net-identity-2 profiles
是否可以为不同的角色提供不同的个人资料?还是我必须:
【问题讨论】:
标签: c# asp.net roles asp.net-identity-2 profiles
您可以像这样使用您的身份用户,然后添加新的实体教师和学生:
public class User: IdentityUser
{
[Required]
[StringLength(100)]
public string FirstName { get; set; }
[Required]
[StringLength(100)]
public string LastName { get; set; }
public DateTime JoinedOn { get; set; }
public virtual Student Student { get; set; }
public virtual Teacher Teacher { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(
UserManager<User, Guid> 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;
}
}
【讨论】:
您可以为不同的角色创建不同的个人资料。假设您有一个 User 表,并且您有一些角色,例如学生、教师、管理员。您可以在用户和学生、用户和教师、用户和管理员之间创建一对一的关系。特定于 Student 的属性保留在 Student 表中。
编辑1:
所以你是对的,你可以创建具有公共属性的用户和具有特定于它们的属性的其他表。
【讨论】: