簡體   English   中英

沒有為“Microsoft.AspNetCore.Identity.UserManager`1[testLogin.Areas.Identity.Data.testLoginUser]”類型注冊服務

[英]No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[testLogin.Areas.Identity.Data.testLoginUser]' has been registered

我想知道這個錯誤的可能問題是什么:

InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[testLogin.Areas.Identity.Data.testLoginUser]' has been registered.

我正在研究.net6

我已經查看了此No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' 已注冊並嘗試應用更改,但它也不起作用。

這是我的用戶 class:

public class testLoginUser : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string email { get; set; }
    public string Password { get; set; }
}

這是我的 _LoginPartial.cshtml:

@using Microsoft.AspNetCore.Identity
@using testLogin.Areas.Identity.Data

@inject SignInManager<testLoginUser> SignInManager
@inject UserManager<testLoginUser> UserManager

我一直在關注一個在線教程,我正在盡我所能將其調整為我當前的 .net 版本,有人能告訴我如何改進自己嗎?

您需要確保已在配置服務中注冊它:

services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>();

沒有注冊它,你不能將它注入到你的視圖中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM