- 错误:**
处理请求时发生未处理的异常。InvalidOperationException:尝试激活"TestApp_03_RazorPage_Identity.Areas.Identity.Pages.Account.RegisterModel"时,无法解析类型"Microsoft. AspNetCore. Identity.用户管理器" 1 [Microsoft. AspNetCore. Identity.标识用户]"的服务。Microsoft.扩展.依赖注入.激活器实用程序. GetService(IServiceProvider sp,类型类型,所需类型,bool是默认参数必需的)
- 详细信息**:我正在按照微软的例子,当我试图设置一个
ApplicationUser
类时,它仍然不起作用。我看到类似的帖子,没有什么对我起作用
- 详细信息**:我正在按照微软的例子,当我试图设置一个
- 程序. cs**
var builder = WebApplication.CreateBuilder(args);
var connectionString =
builder.Configuration.GetConnectionString("MyConnection");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddRazorPages();
- 应用程序用户. cs**
public class ApplicationUser : IdentityUser
{
public string FullName { get; set; }
}
- 应用程序数据库上下文. cs**
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
- _部分登录. cshtml*
@using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
- 寄存器型号**
public class RegisterModel : PageModel
{
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly UserManager<ApplicationUser> _userManager;
private readonly IUserStore<IdentityUser> _userStore;
private readonly IUserEmailStore<IdentityUser> _emailStore;
private readonly ILogger<RegisterModel> _logger;
private readonly IEmailSender _emailSender;
1条答案
按热度按时间rjee0c151#
如果扩展
IdentityUser
,则需要使用ApplicationUser
:而不是: