rob*_*_rg 6 asp.net asp.net-mvc asp.net-core
在 Asp core 3.0 上,当用户单击他们的个人资料“Areas/Identity/Pages/Account/Manage/_layout.cshtml”时,我的布局页面对用户不起作用
当我登录后单击默认电子邮件时,我得到 Manage/Index.cshtml 但没有布局详细信息。像导航一样,忘记密码等的链接没有显示。我不知道是什么导致了这种情况。
我把它放在其他项目上,看到了任何差异,也找不到我的布局不显示的任何原因。
区域/身份/页面/帐户/管理/_layout.cshtml
@{
Layout = "/Areas/Identity/Pages/_Layout.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
Areas/Identity/Pages/Account/Manage/Index.cshtml
@page
@model IndexModel
@{
ViewData["Title"] = "Profile";
ViewData["ActivePage"] = ManageNavPages.Index;
}
Run Code Online (Sandbox Code Playgroud)
区域/身份/页面/帐户/_ViewStart.cshtml
@{
Layout = "/Views/Shared/_Layout.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
试图查看我遗漏了什么或任何其他要检查的地方以显示布局页面。
小智 9
我有同样的问题,我怀疑当您在 startup.ConfigureServices 中替换 services.AddDefaultIdentity 调用时会发生同样的问题 - 在我的情况下,我用 AddIdentity 替换了它,因为我需要将 RoleManager 传递给我的控制器。
这个问题很可能有一个更优雅的解决方案,但我放弃了寻找一个解决方案,因为我发现这个全新的功能没有很好的记录。
这是我解决这个问题的方法:
我假设您已经搭建了身份页面 - 如果没有,请参阅:https : //docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-3.0&tabs=visual -工作室
在 Areas\Identity\Pages\Account\Manage_Layout.cshtml 下的页面中修改布局位置为:
@{
Layout = "/Views/Shared/_Layout.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
现在在您的索引页面 Areas\Identity\Pages\Account\Manage\Index.cshtml 中,您还需要显式设置布局页面:
@page
@model IndexModel
@{
Layout = "_Layout.cshtml";
}
@{
ViewData["Title"] = "Profile";
ViewData["ActivePage"] = ManageNavPages.Index;
}
Run Code Online (Sandbox Code Playgroud)
您还必须在该文件夹下的所有其他页面中明确设置此布局。
小智 6
AddDefaultUI()设置时在启动类中使用
services.AddIdentity<User, Role>().AddDefaultUI()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4026 次 |
| 最近记录: |