【发布时间】:2019-01-03 20:42:44
【问题描述】:
我使用本地用户帐户在 net core 2.2 中创建了项目,并使用脚手架添加了所有身份文件。我在模型文件夹中创建了两个文件 ApplicationUser.cs 和 ApplicationRole.cs。然后我修改了startup.cs 和applicationdbcontext 为用户和角色使用新属性。现在我必须在Areas/Identity 的所有类中将所有关系从IdentityUser 更改为ApplicationUser。我是否遗漏了什么或者这是预期的行为?
在将关系从 IdentityUser 更改为 ApplicationUser 之前出现错误。
在尝试激活“Areas.Identity.Pages.Account.LogoutModel”时,无法解析“Microsoft.AspNetCore.Identity.SignInManager`1[Microsoft.AspNetCore.Identity.IdentityUser]”类型的服务。 私有只读 SignInManager _signInManager;
到
private readonly SignInManager<ApplicationUser> _signInManager;
public class ApplicationRole : IdentityRole
{
public string Description { get; set; }
public string DisplayName { get; set; }
}
public class ApplicationUser : IdentityUser
{
public string Name { get; set; }
public string Surname { get; set; }
public string Fullname { get; set; }
}
startup.cs
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
ApplicationDbContext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
我想确保我没有遗漏或犯错。
【问题讨论】:
-
在您的控制器或视图中 UserManager
更改为 UserManager -
我知道而且我做到了。它有效,但我必须在身份区域中的每个文件/类中进行更改。我正在寻找复杂的解决方案。
标签: .net-core asp.net-identity identity