-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Hello,
I created a new ASP.NET Core web application (Razor Pages with Individual access rights as the authentication option and .NET Core 3.1 as the framework).
1.) I created a new model called "ApplicationUser" that inherits from IdentityUser. I just added 2 new columns FirstName and LastName.
2.) I added the ApplicationUser to the applicationDbContext and migrated it to the database.
3.) I scaffolded all the Identity pages.
4.) I updated the Privacy.cshtml and just added the Authorize attribute on the class level. I just wanted to test out if the user will be redirected to the login page which is working as expected.
5.) After that, I updated the ConfigureServices method in the Startup file.
I removed the line below:
services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores();
and replaced it with the line below:. Since I will be using the ApplicationUser class now instead of the default IdentityUser
services.AddIdentity<IdentityUser, IdentityRole>()
.AddDefaultTokenProviders()
.AddEntityFrameworkStores();
It compiled successfully and the index page is loaded. I then clicked the Privacy page, so it should redirect me to the login page since im not yet authorize. But its throwing out an error.
This localhost page can’t be found
No webpage was found for the web address: https://localhost:44300/Account/Login?ReturnUrl=%2FPrivacy
If I manually add the "Identity" word before the Account in the URL, it will be redirected to the login page. If I revert the changes I made in step 5, the auto redirection works as expected and can find the login page. However, since I want to use the ApplicationUser object, I need to update the ConfigureServices.
Any idea why this is happening? Is there a setting I miss out?
Thanks