使用the article linked by Panagiotis Kanavos,我能够找到解决方案。
在 ASP.NET Core 2.1.0-preview1 中,有一行 .AddDefaultUI(),您不必将其包含在 Startup.cs 中。
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultUI()
.AddDefaultTokenProviders();
然而,在 Core 2.1 的最终发布版本中,同一部分被简化为:
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
解决方案,如果将AddDefaultIdentity 改回AddIdentity,则可以覆盖默认值。 IE。不要包含.AddDefaultUI()(也不要为 UI 搭建脚手架),您可以自己编写。
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
// .AddDefaultUI()
.AddDefaultTokenProviders();
那么,我认为删除/Areas/Identity/文件夹是安全的,但我不是100%
更新:
我清理了我的答案,详细说明了我最终使用的最终解决方案,删除了 ASP.NET Core 2.1 附带的默认身份 UI 剃须刀页面,并改用 MVC。
1) 在Startup.cs,
public void ConfigureServices(IServiceCollection services)
{
// Unrelated stuff commented out...
// BEGIN: Identity Setup (Overrides default identity)
services.AddIdentity<ApplicationUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// END: Identity Setup
services.Configure<IdentityOptions>(options =>
{
// Set your identity Settings here (password length, etc.)
});
// More unrelated stuff commented out...
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// Added after AddMvc()
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = $"/account/login";
options.LogoutPath = $"/account/logout";
options.AccessDeniedPath = $"/account/access-denied";
});
// More unrelated stuff commented out...
}
显然,如果需要,请将 ApplicationUser 和 IdentityRole 替换为您自己的类。
2) 删除 ASP.NET Core 2.1 项目默认提供的 Identity 区域文件夹。
3) 创建一个新的单独的 ASP.NET Core 2.0 项目(不是“2.1”),在项目创建窗口中选择Individual User Account 身份验证。
4) 将 AccountController 和 ManageController 以及对应的 ViewModels 和 Views 从 2.0 项目复制到您的 ASP.NET Core 2.1 项目。
执行上述操作,到目前为止我还没有遇到任何问题。