如果在ASP.NET Core Identity中使用自定义登录页面时遇到此问题,则需要在Startup.cs文件中的ConfigureServices方法中添加以下依赖注入服务代码:
services.AddRazorPages().AddRazorPagesOptions(options =>
{
options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
options.Conventions.AuthorizeAreaPage("Identity", "/Account/Manage/Index");
options.Conventions.AuthorizeAreaPage("Identity", "/Account/Manage/ChangePassword");
options.Conventions.AuthorizeAreaPage("Identity", "/Account/Manage/SetPassword");
options.Conventions.AllowAnonymousToAreaPage("Identity", "/Account/Login");
options.Conventions.AllowAnonymousToAreaPage("Identity", "/Account/Register");
}).AddSignInManager>();
此外,请确保您在登录页面.cshtml文件中的Page指令中包含@model WebApp.Areas.Identity.Pages.Account.LoginModel
,例如:
@page
@model WebApp.Areas.Identity.Pages.Account.LoginModel