c# - 无法从脚手架创建新帐户

标签 c# asp.net-identity entity-framework-core scaffolding

我尝试使用新的 .Net Core 2.1 中的新身份脚手架从头开始创建授权和身份验证,但不断收到此错误。

SqlException:无效的对象名称“AspNetUsers”。

RegisterModel 无法在此行执行:

var result = await _userManager.CreateAsync(user, Input.Password);

IDENTITYHOSTINGSTARTUP.CS

[assembly: HostingStartup(typeof(Authorize.Areas.Identity.IdentityHostingStartup))]
namespace Authorize.Areas.Identity
{
    public class IdentityHostingStartup : IHostingStartup
    {
        public void Configure(IWebHostBuilder builder)
        {
            builder.ConfigureServices((context, services) => {
                services.AddDbContext<AuthorizeContext>(options =>
                    options.UseSqlServer(
                        context.Configuration.GetConnectionString("AuthorizeContextConnection")));

                services.AddDefaultIdentity<AuthorizeUser>()
                    .AddEntityFrameworkStores<AuthorizeContext>()
                    .AddDefaultTokenProviders();
            });
        }
    }
}

最佳答案

此错误通常表明您的数据库中没有 AspNetUsers 表。您是否运行了脚手架中提供的迁移?这可以通过 powershell 或控制台终端来完成。如果使用 powershell 或用于控制台的 dotnet ef database update,导航到 Web 项目并执行 Update-Databasehttps://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/

关于c# - 无法从脚手架创建新帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50806778/

相关文章:

c# - 过滤绑定(bind)列表

c# - 使用 ASP.NET Identity 创建默认用户帐户

asp.net-mvc - 阻止未确认电子邮件的用户登录 ASP.NET MVC Web API Identity(OWIN 安全)

c# - 使用 Azure AD 时将用户重定向到自定义登录页面

c# - 通过 LINQ 加载嵌套属性

c# - 什么相当于 C# 中的 Windows API CreateEvent 函数

c# - XAML 样式属性未被继承

c# - Intellisense 未显示代码隐藏中的新控件

c# - Entity Framework 核心映射问题

c# - 配置DbContext构造函数