无法从脚手架创建新帐户
Unable to Create a new account from 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 table。您 运行 脚手架中提供的迁移了吗?这可以通过 powershell 或控制台终端来完成。导航到 Web 项目并执行 Update-Database
(如果使用 powershell 或 dotnet ef database update
用于控制台)。
https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/
我正在尝试使用新的 .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 table。您 运行 脚手架中提供的迁移了吗?这可以通过 powershell 或控制台终端来完成。导航到 Web 项目并执行 Update-Database
(如果使用 powershell 或 dotnet ef database update
用于控制台)。
https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/