AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Account Management navigation missing after scaffolding the Identity UI

Open rjax opened this issue 8 years ago • 30 comments

This is basically a duplicate of Issue #7827, I would reopen it if I knew how. To recreate the issue:

EDIT by @Rick-Anderson OK, after much mucking around I have found the following:

  • Specifying the layout file in the scaffolding dialog doesn't seem to do anything. I have only made a cursory check of this.
  • To get the navigation working you need to do two things after running the scaffolding:
  1. Add a _viewstart.cshtml to the Manage folder to set the layout
@{
    Layout = "_Layout";
}
  1. Change the layout path in /Areas/Identity/Pages/Account/Manage/_Layout.cshtml from
@{
    Layout = "/Areas/Identity/Pages/_Layout.cshtml";
}

to

@{
    Layout = "/Pages/Shared/_Layout.cshtml";
}

EDIT by @Rick-Anderson

The layout generated by the templates is correct. See this GithHub comment for details.

With ASP.NET Core 3.1, the only problem with navigation after scaffolding is https://github.com/dotnet/Scaffolding/issues/1350, the links on the 2FA page are not styled correctly.

To repo:

dotnet new webapp -au Individual -uld -o RPauth
cd RPauth
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet aspnet-codegenerator identity -dc RPauth.Data.ApplicationDbContext 

Register > sign in > select login > select 2FA

To fix, replace class="btn btn-default" with class="btn btn-primary" like the rest of the templates.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

rjax avatar Sep 06 '18 20:09 rjax

@rjax did you follow the VS or CLI instructions. I think the CLI instructions need to specify the layout file. From dotnet aspnet-codegenerator identity -h

--layout|-l : Specify a custom layout file to use.

Rick-Anderson avatar Sep 06 '18 22:09 Rick-Anderson

It's not clear to me what you're suggesting. I'm using VS 2017. The dialog that is opened when adding the scaffolding allows me to 'Select an existing layout page, or specify a new one:' or '(Leave empty if it is set in a Razor _viewstart file). Up till now I have left this empty. In response to you're question I have tried ~/Pages/Shared/_Layout.cshtml and /Areas/Identity/Pages/Account/Manage/_Layout.cshtml. Neither of these made any difference. Do you have another suggestion?

rjax avatar Sep 07 '18 07:09 rjax

OK, after much mucking around I have found the following:

  • Specifying the layout file in the scaffolding dialog doesn't seem to do anything. I have only made a cursory check of this.
  • To get the navigation working you need to do two things after running the scaffolding:
  1. Add a _viewstart.cshtml to the Manage folder to set the layout
@{
    Layout = "_Layout";
}
  1. Change the layout path in /Areas/Identity/Pages/Account/Manage/_Layout.cshtml from
@{
    Layout = "/Areas/Identity/Pages/_Layout.cshtml";
}

to

@{
    Layout = "/Pages/Shared/_Layout.cshtml";
}

rjax avatar Sep 07 '18 13:09 rjax

@rjax

'(Leave empty if it is set in a Razor _viewstart file). Up till now I have left this empty.

The instructions say to use ~/Pages/Shared/_Layout.cshtml

This problem was reported in #7827 but after upgrading VS and .NET Core SDK, he can't reproduce the problem. I can't reproduce the problem when following the instructions.

Rick-Anderson avatar Sep 07 '18 22:09 Rick-Anderson

Add a _viewstart.cshtml to the Manage folder to set the layout

The scaffolder adds that

Rick-Anderson avatar Sep 07 '18 22:09 Rick-Anderson

I'm using VS Enterprise 2017 v15.8.2, .NET Framework 4.7.02558 Microsoft.AspNetCore.App 2.1.1, Microsoft.NETCore.App 2.1.0, Microsoft.VisualStudio.Web.CodeGeneration.Design 2.1.3. I just created a new project and added the scaffolding again while setting the layout to ~/Pages/Shared/_Layout.cshtml as instructed:

  • _viewstart.cshtml is included in the the Identity/Pages folder with Layout = "/Pages/Shared/_Layout.cshtml"; This is the correct result and is the same as when the layout is not set in the scaffolding dialog.
  • Identity\Pages\Account\Manage_Layout.cshtml is created with Layout = "/Areas/Identity/Pages/_Layout.cshtml"; This incorrect. the layout needs to be Layout = "/Pages/Shared/_Layout.cshtml";
  • No _viewstart.cshtml has been added to the Identity\Pages\Account\Manage folder. This results in all of the pages in the Manage folder using the layout /Pages/Shared/_Layout.cshtml as set in Identity/Pages/_viewstart.cshtml instead of Identity/Pages/Account/Manage/_Layout.cshtml.

I can't speak for Yanal-Yves (https://github.com/aspnet/Docs/issues/7827) but I have created at least 5 projects in the last couple of days using the environement described above and I am able to reproduce the issue consistently. That said, the problem seems to be with the scaffolder and not the documentation although it might be useful to show the resulting file structure with a short discussion about what you get. Thanks for your time and effort in trying to help.

rjax avatar Sep 08 '18 10:09 rjax

Why are you using .NET Framework and not .NET Core? Are you using RP or MVC?

Can you repo the isssue when you're targeting .NET Core? @rjax we need to figure out how you can reproduce the issue and we can't. What's different?

Rick-Anderson avatar Sep 08 '18 18:09 Rick-Anderson

@rjax this is in my Areas\Identity\Pages\Account\Manage\_Layout.cshtml project that works correctly:

@{ 
    Layout = "/Areas/Identity/Pages/_Layout.cshtml";
}

Rick-Anderson avatar Sep 08 '18 18:09 Rick-Anderson

You can see my layout banner works

image

Rick-Anderson avatar Sep 08 '18 18:09 Rick-Anderson

I think that we have a misunderstanding here. When I spoke of navigation I was referring to the navigation that appears with in the form, not the black navigation bar at the top of the page. If I knew how to upload an image I would show you exactly what I mean. In any case your image shows the problem as well. I you add identity to your project and don't override the GUI all of the account management pages include navigation on the left hand side of the form; Profile, Password, Two Factor Authentication and Personal Data. These are missing in you screen shot. If you set the layouts as detailed above these items will be be added to the form.

rjax avatar Sep 13 '18 13:09 rjax

image

isjax avatar Sep 13 '18 13:09 isjax

@rjax thanks for the clarification. We'll get this fixed.

Rick-Anderson avatar Sep 13 '18 21:09 Rick-Anderson

On Sep 19, 2018 6:48 PM, ameteiver [email protected] wrote:

Any suggested workaround available to get the navigation back in place?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/aspnet/Docs/issues/8440#issuecomment-422854424, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ApO0wCKjbHl_TcS67ZtsarwaRSItbqQzks5ucmc6gaJpZM4WdrI0.

The workaround is described in the thread.

isjax avatar Sep 19 '18 16:09 isjax

If you have your views in the "Views" folder then when applying the fix provided by @rjax be sure to change the path from Layout = "/Pages/Shared/_Layout.cshtml"; to Layout = "/Views/Shared/_Layout.cshtml";. With this in place everything worked perfectly for my team.

rahicks26 avatar Sep 19 '18 21:09 rahicks26

If someone's still confused, I'd like to add that in @rjax's reply the /Areas/Identity/Pages/Account/Manage/_ViewStart.cshtml

@{
    Layout = "_Layout";
}

didn't work in my case (Rider 2018.2.3) because it was pointing to the _Layout.cshtml in /Pages/Shared/

1

but adding .cshtml seems to fix the path, and the side navigation bar is finally visible.

@{
    Layout = "_Layout.cshtml";
}

2

matteberna avatar Oct 22 '18 19:10 matteberna

Using ASP.NET Core SDK 2.2.101 I had the same problem. The problem was the _ViewStart.cshtml file was not added by the scaffold process. Add a default _ViewStart.cshtml page fixed the issue.

MarxITSolutions avatar Dec 13 '18 23:12 MarxITSolutions

Reason for this issue.

While using AddDefaultIdentity, system will dynamically generate the required _Layout & _ViewStart pages. But when we used AddIdentity system will not allow to add the dynamic pages during the run time. So we need to manually create all the required layout pages.

Solution for this issue.

  1. Create one _ViewStart.cshtml in Identity/Pages/Account/Manage(If not exists)

    @{ Layout = "_Layout"; }

  2. Identity/Pages/Account/Manage/_Layout.cshtml having like "Layout = "/Areas/Identity/Pages/_Layout.cshtml";" we need to change this line like Layout = "/Pages/Shared/_Layout.cshtml";. Because _Layout.cshtml file doesn't have in the "/Areas/Identity/Pages/" folder.

Notes: Based on your folder structure this _Layout.cshtml will be available on "Views/Shared/_Layout.cshtml"

  1. Compile and Run the solution and test it. If its not cleared then follow the below steps also.

  2. Create one _ViewStart.cshtml in Identity/Pages folder(If not exists)

    @{ Layout = "_Layout"; }

  3. Create one _layout.csthml in Identity/Pages folder(If not exists)

@{ Layout = "/Pages/Shared/_Layout.cshtml"; }

Notes: Based on your folder structure this _Layout.cshtml will be available on "Views/Shared/_Layout.cshtml"

  1. Now compile and run your solutions.

Happy Coding!!!.

gopal-k avatar Dec 20 '18 09:12 gopal-k

Just to say I had this issue , doing 1 and 2 above (I didn't had a _ViewStart.cshtml) fixed it. Thanks

rmarinho avatar Jan 10 '19 00:01 rmarinho

+1 for this strange issue. Had me chasing my tail for a while. Trial and error of the methods mentioned worked eventually. Missing _ViewStart file inside /Areas/Identity/Pages/Account/Manage was the main one I think.

HarleyBartles avatar Jan 11 '19 14:01 HarleyBartles

Thanks @rjax for the solution!

danielmackay avatar Feb 24 '19 01:02 danielmackay