br3*_*3nt 4 asp.net-identity asp.net-core-mvc asp.net-core asp.net-core-5.0
我正在遵循这些指南:
遵循第一个指南后,我得到了我对“身份/帐户/管理”页面的期望:

然而,在遵循第二个指南后,布局被破坏了。侧面菜单丢失。该应用程序不再找到Areas/Identity/Pages/Account/Manage/_Layout.cshtml,我不明白为什么。
这是 git diff。
namespace WebIdentity.Areas.Identity
{
public class IdentityHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) => {
services.AddDbContext<IdentityDbContext>(options =>
options.UseSqlServer(
context.Configuration.GetConnectionString("IdentityDbContextConnection")));
- services.AddDefaultIdentity<User>(options => options.SignIn.RequireConfirmedAccount = true)
- .AddEntityFrameworkStores<IdentityDbContext>();
+ services
+ .AddIdentity<User, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
+ .AddEntityFrameworkStores<IdentityDbContext>()
+ .AddDefaultTokenProviders();
+
+ services
+ .AddMvc()
+ .AddRazorPagesOptions(options =>
+ {
+ options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
+ options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
+ });
+
+ services.ConfigureApplicationCookie(options =>
+ {
+ options.LoginPath = $"/Identity/Account/Login";
+ options.LogoutPath = $"/Identity/Account/Logout";
+ options.AccessDeniedPath = $"/Identity/Account/AccessDenied";
+ });
+
+ services.AddSingleton<IEmailSender, EmailSender>();
});
}
}
Run Code Online (Sandbox Code Playgroud)
小智 9
只需在 Areas/Identity/Pages/Account/Manage 文件夹中添加 _ViewStart.cshtml 即可:
@{
ViewData["ParentLayout"] = Layout;
Layout = "_Layout.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1702 次 |
| 最近记录: |