On Asp core 3.0 my layout page is not working for a user when they click their profile "Areas/Identity/Pages/Account/Manage/_layout.cshtml"
When I click on the default email after logging in I get Manage/Index.cshtml but no layout details. Like the navigation, links to forgot passwords etc are not displaying. I have no idea what can cause this.
I put it against other projects and see any discrepancies and cannot find any reason why my layout is not displaying.
Areas/Identity/Pages/Account/Manage/_layout.cshtml
@{
Layout = "/Areas/Identity/Pages/_Layout.cshtml";
}
Areas/Identity/Pages/Account/Manage/Index.cshtml
@page
@model IndexModel
@{
ViewData["Title"] = "Profile";
ViewData["ActivePage"] = ManageNavPages.Index;
}
Areas/Identity/Pages/Account/_ViewStart.cshtml
@{
Layout = "/Views/Shared/_Layout.cshtml";
}
Trying to see what I'm missing or any other place to check to get the layout page to display.
I had the same issue which I suspect happens when you replace the services.AddDefaultIdentity call in startup.ConfigureServices - In my case I replaced it with AddIdentity as I needed to pass the RoleManager to my controllers.
There is most probably a more elegant solution to this problem but I gave up looking for one as I find this whole new functionality to be poorly documented.
Here is how I solved for this:
I am assuming you have scaffolded the Identity pages already - If not please see: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-3.0&tabs=visual-studio
In the page under Areas\Identity\Pages\Account\Manage_Layout.cshtml modify the layout location to:
@{
Layout = "/Views/Shared/_Layout.cshtml";
}
Now in your Index page Areas\Identity\Pages\Account\Manage\Index.cshtml you also need to explicitly set a layout page:
@page
@model IndexModel
@{
Layout = "_Layout.cshtml";
}
@{
ViewData["Title"] = "Profile";
ViewData["ActivePage"] = ManageNavPages.Index;
}
You'll also have to explicitly set this layout in all other pages under that folder.
Use AddDefaultUI()
in startup class when setting
services.AddIdentity<User, Role>().AddDefaultUI()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With