Reputation: 1
I'm trying to scaffold identity pages (Login and Register) in my ASP.NET Core application. However, when I select the pages and my DbContext class, I cannot select my custom user class, ApplicationUser
, because the User Class field is disabled.
Here is my DbContext class definition :
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
My custom user and role :
public class ApplicationUser : IdentityUser
public class ApplicationRole : IdentityRole
I have references to my ApplicationUser
and ApplicationRole
classes in the context. Additionally, I attempted to roll back the version of the Microsoft.AspNetCore.Identity.UI package, but the issue persists.
What could be causing the User Class field to be disabled, and how can I enable it to select my custom user class?
i tried manually to replace IdentityUser
with ApplicationUser
in these files : Register.cshtml.cs and Login.cshtml.cs, but it didn't work and i got this error :
InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'MyApp.Web.Areas.Identity.Pages.Account.RegisterModel'.
Upvotes: 0
Views: 98
Reputation: 1
Solution :
The solution to this problem is to go through every scaffolded page and replace IdentityUser
with ApplicationUser
Example :
// NOT Working
public class LoginModel: PageModel {
private readonly SignInManager <IdentityUser> _signInManager;
private readonly ILogger <LoginModel> _logger;
public LoginModel(SignInManager <IdentityUser> signInManager, ILogger <LoginModel> logger) {
_signInManager = signInManager;
_logger = logger;
}
}
// Working
public class LoginModel: PageModel {
private readonly SignInManager <ApplicationUser> _signInManager;
private readonly ILogger <LoginModel> _logger;
public LoginModel(SignInManager <ApplicationUser> signInManager, ILogger <LoginModel> logger) {
_signInManager = signInManager;
_logger = logger;
}
}
Upvotes: 0