Can somebody please help me? I am having trouble running the app after scaffolding Identity. It keeps showing the No service for type "'Microsoft.AspNetCore.Identity.UserManager`1[OAS.Model.User]' has been registered." exception. I have searched thorugh the Internet and checked the _LoginPartial.cshtml as well. The @inject part is correct but it is still not working. Here are my code files:
_LoginPartial.cshtml:
@using Microsoft.AspNetCore.Identity
@using OAS.Model
@inject SignInManager<User> SignInManager
@inject UserManager<User> UserManager
<ul >
@if (SignInManager.IsSignedIn(User))
{
<li >
<a id="manage" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">Hello @UserManager.GetUserName(User)!</a>
</li>
<li >
<form id="logoutForm" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Page("/Index", new { area = "" })">
<button id="logout" type="submit" >Logout</button>
</form>
</li>
}
else
{
<li >
<a id="register" asp-area="Identity" asp-page="/Account/Register">Register</a>
</li>
<li >
<a id="login" asp-area="Identity" asp-page="/Account/Login">Login</a>
</li>
}
</ul>
User.cs file:
public class User : IdentityUser
{
[Required]
public string Description { get; set; }
}
I have no idea what to change next.
CodePudding user response:
looks like you're trying to use the UserManager
, but it has not been registered with the service container.
try this:
services.AddIdentity<User, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>();