简体   繁体   中英

ASP.Net Core Identity in separate class errors

I'm working with ASP.Net Core and attempting to move some of the Identity components into a separate assembly. I moved ApplicationDbContext and ApplicationUser into an assembly called DataModels . ( ApplicationUser is in the Models folder/namespace of DataModels .)

In the WebApplication Startup.cs I reference this assembly and everything compiles fine. I updated the AccountController to correctly reference this as well.

When I start up my app, I receive this:

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.

The type or namespace name 'ApplicationUser' could not be found (are you missing a using directive or an assembly reference?)

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

My Startup.cs has this:

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>();
}

Obviously I'm not specifying the DataModels assembly somewhere, I'm just not sure where.

Found that it was referenced in these files:

_LoginPartial.cshtml
Login.cshtml

I needed to update those files with this:

@using DataModels.Models

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM