- 确保Identity NuGet包的版本与ASP.NET Core应用程序的版本兼容。
- 确保已在IdentityDbContext中设置了正确的连接字符串。
- 确认IdentityDbContext类已正确地从IdentityDbContext DbContext基类继承,并且IdentityUser和IdentityRole类型已正确地从IdentityUser和IdentityRole基类继承。
- 确保对Identity服务的正确配置已添加到Startup.cs文件中。
- 确保在Startup.cs文件中启用了Identity服务的自动UI生成。
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddDbContext(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity()
.AddEntityFrameworkStores();
services.AddControllersWithViews();
services.AddRazorPages();
// ...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// ...
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapRazorPages();
});
// ...
}
- 如果仍然存在问题,请考虑使用Visual Studio的Identity Scaffolding选项手动添加Identity UI。