Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout not working on asp.net core 3.0 for user profile

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.

enter image description here

enter image description here

like image 874
robert_rg Avatar asked Oct 31 '19 22:10

robert_rg


2 Answers

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.

like image 82
Pierre Custeau Avatar answered Sep 24 '22 18:09

Pierre Custeau


Use AddDefaultUI() in startup class when setting

services.AddIdentity<User, Role>().AddDefaultUI() 
like image 41
Drumi Stoyanov Avatar answered Sep 26 '22 18:09

Drumi Stoyanov