我想在asp.net核心搭建一个CRUD管理员。但是Application user类不包括在列出的模型类中。
我尝试创建另一个不从identity user继承的类
public class Investors
{
public string FullName { get; set; }
public string Country { get; set; }
public string Project { get; set; }
public string Telephone { get; set; }
} 然后,当我尝试搭建CRUD操作时,模型类中列出了投资者模型。我用过它,但当我运行我的项目时,我无法看到已经注册的用户列表。
这是我创建的Application User类。
public class ApplicationUser : IdentityUser
{
public string FullName { get; set; }
public string Country { get; set; }
public string Project { get; set; }
public string Telephone { get; set; }返回已注册用户列表的实际模型类应该是Application user类(但在搭建CRUD razor页面时没有列出它),因为它是我在创建用户时使用的类。
发布于 2018-12-28 14:33:23
作为我的测试,我可以得到同样的结果。它似乎与为Identity定义的Identity classes有关。
因此,您应该避免从控制器直接通过DbContext操作ApplicationUser。
对于继承自IdentityUser的ApplicationUser,用户将包含许多像ConcurrencyStamp和SecurityStamp这样的属性。如果您通过DbContext直接从Controller创建用户,您可能无法为它们设置值,这将导致您的Identity Feature不稳定。
不需要用ApplicationUser创建新的控制器,你可以使用AccountController和ManageController在比Asp.Net Core 2.1更早的时候控制ApplicationUser。对于Asp.Net Core 2.1和更高版本,您可以尝试使用Identity Scaffold来自定义Identity。
对于带有CRUD的ApplicationUser,您可以使用注入UserManager<ApplicationUser>来创建控制器。
https://stackoverflow.com/questions/53899423
复制相似问题