2 回答
TA贡献1801条经验 获得超15个赞
如果您想ApplicationUser为您的身份使用自定义而不是默认IdentityUser。您需要在声明模型后进行一些更改。
1.在dbContext中:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
2.在startup.cs中:
services.AddIdentity<ApplicationUser,IdentityRole>(config => {
config.SignIn.RequireConfirmedEmail = true;
})
...
3.在你的 /Shared/_LoginPartial.cshtml
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
TA贡献1812条经验 获得超5个赞
IdentityUser不是您的dbContext. 你需要UserManager<IdentityUser>改用。
你的ApplicationUsersController班级应该是这样的
public class ApplicationUsersController : Controller
{
private readonly ApplicationDbContext _context;
private readonly UserManager<IdentityUser> _userManager;
public ApplicationUsersController(ApplicationDbContext context,
UserManager<IdentityUser> userManager;)
{
_context = context;
_userManager = userManager;
}
// GET: Administrator/ApplicationUsers
public async Task<IActionResult> Index()
{
return View(await _userManager.Users.Cast<ApplicationUser>().ToListAsync());
}
}
- 2 回答
- 0 关注
- 162 浏览
添加回答
举报