Since asp.net core 2.1 the MVC is not supported as default model with Identity. I want to run Identity with MVC in asp.net core 2.2
Make a long story short. This is a asp.net 4.6.2 site with local db that I want upgrade to asp.net core 2.2 . I thought that this would be simple thing. So wrong I was. So what did I do:
6.1 ConcurrencyStamp
6.2 NormalizedUserName
6.3 NormalizedEmail
6.4 Changed name LockoutEnd? to LockoutEnd
The system builds but still I cant get it to use the Account controller. I have followed the steps in https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.2 without no avail. It seems what I do I can't get it to read the mvc controller even after I scaffolded the Identity.
I think the difference in implementations of Identity in asp.net core 2.X Identity is either to high or to narrow regarding earlier implementations.
Included part of my startup
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
// services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddRazorPagesOptions(options =>
{
options.AllowAreas = true;
//options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
//options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
});
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = $"/Account/Login";
options.LogoutPath = $"/Account/Logout";
options.AccessDeniedPath = $"/Account/AccessDenied";
});
// using Microsoft.AspNetCore.Identity.UI.Services;
services.AddSingleton<IEmailSender, EmailSender>();
}
I want to use MVC with Identity Core 2.2 with an old database from Identity .Net.
So any suggestions?
It's not clear what you're doing exactly, but it sounds like you've scaffolded the Identity Razor Pages into your project. If that's the case, those are going to take precedent over your controller, since it's a more physical route.
All the other code looks good. You're using AddIdentity
instead of AddDefaultIdentity
(so the default UI is not included). Assuming you've actually created an AccountController
and your routing is set up correctly, then it should work, as long as you don't have the default UI physically scaffolded into your project.