【问题标题】:ASP.Net Core Identity in separate class errorsASP.Net Core Identity 在单独的类错误中
【发布时间】:2016-08-30 19:25:08
【问题描述】:

我正在使用 ASP.Net Core 并尝试将一些身份组件移动到单独的程序集中。我将ApplicationDbContextApplicationUser 移动到一个名为DataModels 的程序集中。 (ApplicationUser 位于Models 文件夹/命名空间DataModels。)

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

当我启动我的应用程序时,我会收到以下信息:

编译处理此请求所需的资源时出错。请查看以下具体错误详情并适当修改您的源代码。

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

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

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

显然我没有在某处指定 DataModels 程序集,我只是不确定在哪里。

【问题讨论】:

    标签: c# asp.net-core asp.net-identity


    【解决方案1】:

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

    _LoginPartial.cshtml
    Login.cshtml
    

    我需要用这个来更新这些文件:

    @using DataModels.Models
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-29
      • 2023-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 2020-06-08
      • 2016-08-20
      相关资源
      最近更新 更多