作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法在 IdentityUser
、IdentityRole
和 IdentityDbContext 中创建自定义用户和角色而不指定 TKey
?我问是因为它似乎认为我不再想要自动生成的主键 string
Id
而我绝对想要。执行我在下面所做的操作时,UserManager.Create(user, password)
将失败,并在 Id
上出现 EntityValidationError
。
public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
[Required]
[StringLength(50)]
public string FirstName { get; set; }
[Required]
[StringLength(50)]
public string LastName { get; set; }
}
public class ApplicationUserLogin : IdentityUserLogin
{
}
public class ApplicationUserClaim : IdentityUserClaim
{
}
public class ApplicationUserRole : IdentityUserRole
{
}
public class ApplicationRole : IdentityRole<string, ApplicationUserRole>
{
[Required]
[StringLength(50)]
public string ProperName { get; set; }
[Required]
public string Description { get; set; }
}
public class MyAppDb : IdentityDbContext<ApplicationUser, ApplicationRole, string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public MyAppDb()
: base("MyAppDb")
{
}
public static MyAppDb Create()
{
return new MyAppDb();
}
}
最佳答案
我仍在学习这个新的 ASP.NET Identity 系统,但您是否尝试过像这样省略泛型类型:
public class ApplicationUser : IdentityUser
{
[Required]
[StringLength(50)]
public string FirstName { get; set; }
[Required]
[StringLength(50)]
public string LastName { get; set; }
}
同样适用于 ApplicationRole
MyAppDb
看起来像这样:
public class MyAppDb: IdentityDbContext<ApplicationUser>
默认情况下,ID 将是数据库中自动生成的 GUID 的字符串
关于asp.net - 有没有办法在不指定 IdenitityUser、IdentityRole 和 IdentityDbContext 上的 TKey 的情况下创建自定义用户和角色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22724938/
有没有办法在 IdentityUser、IdentityRole 和 IdentityDbContext 中创建自定义用户和角色而不指定 TKey string ?我问是因为它似乎认为我不再想要自动生
我是一名优秀的程序员,十分优秀!