ASP.Net Core Identity中单独的类错误

本文关键字:错误 单独 Net Core Identity ASP | 更新日期: 2023-09-27 18:04:42

我正在与ASP合作。Net Core并试图将一些Identity组件移动到一个单独的程序集中。我把ApplicationDbContextApplicationUser移到一个叫做DataModels的集合中。(ApplicationUserDataModelsModels文件夹/命名空间中)

在WebApplication Startup.cs中,我引用了这个程序集,一切都编译得很好。我更新了AccountController以正确地引用它。

当我启动我的应用程序时,我收到这个:

在编译处理此请求所需的资源期间发生错误。请查看以下具体的错误细节,并适当修改您的源代码。

类型或命名空间名称'ApplicationUser'找不到(您是否缺少using指令或程序集引用?)

public SignInManager<ApplicationUser> SignInManager { get; private set; }

My Startup.cs有这个:

using DataModels.Models;
...
public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddDbContext<DataModels.ApplicationDbContext>(options =>
        options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    services.AddIdentity<ApplicationUser, IdentityRole>()
        .AddEntityFrameworkStores<DataModels.ApplicationDbContext>()
        .AddDefaultTokenProviders();
    services.AddMvc();
    // Add application services.
    services.AddTransient<IEmailSender, AuthMessageSender>();
    services.AddTransient<ISmsSender, AuthMessageSender>();
}

显然我没有指定某个地方的数据模型程序集,我只是不确定在哪里。

ASP.Net Core Identity中单独的类错误

发现它在这些文件中被引用:

_LoginPartial.cshtml
Login.cshtml

我需要这样更新这些文件:

@using DataModels.Models