Using the article linked by Panagiotis Kanavos, I was able to reach a solution.
From the ASP.NET Core 2.1.0-preview1, there was a line .AddDefaultUI()
, which you didn't have to include in Startup.cs
.
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultUI()
.AddDefaultTokenProviders();
In the final release version of Core 2.1 however, the same section was simplified to:
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
The solution, if you change AddDefaultIdentity
back to AddIdentity
, you can override the defaults. I.E. don't include .AddDefaultUI()
(and also don't scaffold the UI) and you can write your own.
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<ApplicationDbContext>()
// .AddDefaultUI()
.AddDefaultTokenProviders();
Then, I think it's safe to delete the /Areas/Identity/
folder, but I'm not 100%
Update:
I cleaned up my answer to detail the final solution I ended up going with, to remove the default identity UI razor pages that come with ASP.NET Core 2.1 and and use MVC instead.
1) In 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...
}
And obviously, replace both ApplicationUser
, and IdentityRole
with your own classes if required.
2) Delete the Area folder for Identity that came default with your ASP.NET Core 2.1 project.
3) Create a new separate ASP.NET Core 2.0 project (not "2.1"), with Individual User Account
authentication selected in the project creation window.
4) Copy the AccountController
and ManageController
, with the corresponding ViewModels
and Views
, from the 2.0 project to your ASP.NET Core 2.1 project.
Doing the above, I haven't run into any issues so far.
/Identity/Account/
, which appears not to be a recommended option using the UI. – MagicIdentity UI
package. It's used so you don't have to create/handle/manage the 50+ files used by the scaffolded UI. If you want to modify the UI, just don't use the package. You can generate the files withdotnet aspnet-codegenerator identity -dc WebApplication1.Data.ApplicationDbContext
and modify them. – TamicaIdentity UI
package does, why it was created and how to generate the razor pages so you can modify them. – Tamica--useDefaultUI
parameter to generate and customize all the pages. – Tamica