Reputation: 1099
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();
});
}
}
}
Upvotes: 2
Views: 583
Reputation: 276
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/
Upvotes: 3