【发布时间】:2022-11-14 06:49:25
【问题描述】:
我有 ASP.net 核心 **WebAPI ** 项目,之后我在这个项目中创建了 Scaffolded item witch Identity。如何将默认页面更改为 Identity/page/login.cshtml 而不是 ~/swagger/index.html 谢谢
将默认页面从 ~/swagger/index.html 更改为 Identity/page/login.cshtml 谢谢
我的代码在这里 应用用户.cs
public class AppUser: IdentityUser <int>
{
public string FullName { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
}
程序.cs
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = $"/Identity/Account/Login";
options.LogoutPath = $"/Identity/Account/Logout";
options.AccessDeniedPath = $"/Identity/Account/AccessDenied";
});
AppDbContext.cs
public class AppDbContext : IdentityDbContext<AppUser, IdentityRole<int>, int>
{
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
{
}
...........................................
}
_LoginPartial.cshtml
@using Claim.Data.Entities
@using Microsoft.AspNetCore.Identity
@inject SignInManager<AppUser> SignInManager
@inject UserManager<AppUser> UserManager
当我测试点击登录进入登录页面
错误: InvalidOperationException:尝试激活“XXXXXXX.Areas.Identity.Pages.Account.LoginModel”时,无法解析“Microsoft.AspNetCore.Identity.SignInManager`1[Microsoft.AspNetCore.Identity.IdentityUser]”类型的服务。
【问题讨论】:
-
查看 Properties 文件夹中的
LaunchSettings.json文件和 google"launchUrl": "招摇", -
谢谢汤普森,我在 Program.cs builder.Services.AddControllersWithViews().AddRazorPagesOptions(options => { options.Conventions.AddAreaPageRoute("Identity", "/Account/Login", ""); });还修改了 LaunchSettings.Json 在尝试激活“XXXXXXX.Areas.Identity.Pages”时出现此错误 InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.SignInManager`1[Microsoft.AspNetCore.Identity.IdentityUser]'。 Account.LoginModel'。
-
你能分享你的项目结构吗?屏幕截图或项目层次结构就可以了。
-
嗨 Md Farid Uddin Kiron 我添加了代码
-
你能在你的 program.cs 中分享更多关于身份配置的信息吗?
标签: api asp.net-core asp.net-core-mvc