2

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 Answer 1

3

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://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/

1
  • Error has been fixed. Thanks, anyways. And yes...I forgot to run the migration and update-database. See, in previous versions, you didn't need to do all that. Still getting used to this new version 2.1 Jun 12, 2018 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.