Unable to Create a new account from Scaffolding

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

Question

I'm trying to create authorization and authentication from scratch using the new Identity scaffolding in the new .Net Core 2.1 but keep getting this error.

SqlException: Invalid object name 'AspNetUsers'.

RegisterModel fails to execute on this line:

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();
            });
        }
    }
}
1
2
6/11/2018 11:24:20 PM

Accepted Answer

This error usual suggests that you do not have the AspNetUsers table in your database. Have you ran the migrations provided in the scaffold? This can be done through either a powershell or console terminal. Navigate to the web project and execute Update-Database if using powershell or dotnet ef database update for console. https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/

3
6/12/2018 6:59:21 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow