我正在遵循这些指南:
但是,在遵循第二个指南后,布局被破坏了。侧面菜单丢失。该应用程序不再找到
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>();
});
}
}
只需在 Areas/Identity/Pages/Account/Manage 文件夹中添加 _ViewStart.cshtml 即可:
@{
ViewData["ParentLayout"] = Layout;
Layout = "_Layout.cshtml";
}
调用
AddDefaultIdentity
类似于调用以下内容:
1:添加身份
2:添加默认UI
3:添加默认令牌提供商
您需要在您的
default UI
中添加startup
,如下所示(添加.AddDefaultUI()
):
services
.AddIdentity<User, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
.AddDefaultUI()
.AddEntityFrameworkStores<IdentityDbContext>()
.AddDefaultTokenProviders();
您可以在
AddDefaultIdentity
这里查看更多详细信息。
上面 Jeroen de Jong 给出的答案是正确的,在搭建身份页面后我也在同样的问题上浪费了几个小时。
只需在 Areas/Identity/Pages/Account/Manage 文件夹中添加 _ViewStart.cshtml 即可:
@{
ViewData["ParentLayout"] = Layout;
Layout = "_Layout.cshtml";
}