ASP.NET注册按钮来自标识引发错误

xfyts7mz  于 2023-05-02  发布在  .NET
关注(0)|答案(1)|浏览(151)

我将身份添加到我的Web应用程序中,并希望在运行时单击“添加”,“注册”,但一个特定的错误毁了我:
InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager 1[果园。尝试激活“果园”时,“实体。用户]”。Areas.Identity.Pages.Account.注册模型'`
这是用户实体的代码:

using Microsoft.AspNetCore.Identity;

namespace Orchard.Entities
{
    public class User : IdentityUser
    {
        public override string Id { get; set; }
        public string NickName { get; set; }
        public Address Address { get; set; }
        public List<Messages> Messages { get; set; } = new List<Messages>();

    }
}

有什么不对吗?
我用,,User”和,,IdentityUser”尝试了这个,它似乎只对IdentityUser有效,但我不知道它是如何工作的:

builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true).AddEntityFrameworkStores<OrchardDBContext>();
k10s72fa

k10s72fa1#

InvalidOperationException:无法解析类型“Microsoft”的服务。AspNetCore.Identity.UserManager1[果园.尝试激活“果园”时,“实体。用户]”。Areas.Identity.Pages.Account.注册模型'从你的错误信息来看,我猜你已经在你的果园中使用了private SignInManager signInManager;。Areas.Identity.Pages.Account.RegisterModel,但您注册了AddDefaultIdentity`
尝试注册如下:

builder.Services.AddIdentity<User, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true).AddEntityFrameworkStores<OrchardDBContext>();

相关问题