dotnet / Scaffolding

Code generators to speed up development.
MIT License
635 stars 227 forks source link

Scaffolded Identity "Manage" Layout Refers to Unscaffoldable Layout Page #1225

Open analogrelay opened 4 years ago

analogrelay commented 4 years ago

From @pm64 on Wednesday, January 8, 2020 7:04:03 PM

Describe the bug

The scaffolded Areas\Identity\Pages\Account\Manage\_Layout.cshtml page references "/Areas/Identity/Pages/_Layout.cshtml" as its layout. This page is not present in the project template and is not available for scaffolding.

To Reproduce

  1. In VS2019, create a new ASP.Net Core web application using "Individual User Accounts" authentication
  2. Right-click project node in Solution Explorer, select Add | New Scaffolded Item...
  3. Use the scaffolder to add the Identity page Areas\Identity\Pages\Account\Manage_Layout.cshtml to the project
  4. Observe that the generated _Layout.cshtml references "/Areas/Identity/Pages/_Layout.cshtml" as its layout. This page does not exist in the project template and is not itself available for scaffolding.

Notes

Further technical details

Runtime Environment: OS Name: Windows OS Version: 10.0.18363 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support): Version: 3.1.0 Commit: 65f04fb6db

.NET Core SDKs installed: 3.1.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Copied from original issue: dotnet/aspnetcore#18200

analogrelay commented 4 years ago

From @blowdart on Wednesday, January 8, 2020 8:07:49 PM

@danroth27 This seems to be blazor specific.

analogrelay commented 4 years ago

From @pm64 on Wednesday, January 8, 2020 8:13:25 PM

@blowdart @danroth27 I thought so at first, but then confirmed that traditional web apps are also affected. What leads you to this conclusion? It's quite possible I missed something.

analogrelay commented 4 years ago

From @blowdart on Wednesday, January 8, 2020 8:15:59 PM

Ah that wasn't clear from the issue, as the one you linked to was blazor and no-one has brought this up before.

analogrelay commented 4 years ago

From @blowdart on Wednesday, January 8, 2020 8:16:52 PM

@javiercn Is this a bug, or are we missing something?

analogrelay commented 4 years ago

From @javiercn on Wednesday, January 8, 2020 8:21:52 PM

@blowdart That sounds like a bug.

The scaffolder should detect (within reason) whether the user is using the included layout or has overridden it with the one on the page and provide the path to the right layout on the scaffolded code.

(It can determine what layout is being used by the presence of the _ViewImports file in /Areas/Identity/Pages)

analogrelay commented 4 years ago

From @blowdart on Wednesday, January 8, 2020 8:26:04 PM

@anurse Can you move this to scaffolding repo please?

analogrelay commented 4 years ago

From @pm64 on Thursday, January 9, 2020 1:52:11 AM

@blowdart can we remove the area-blazor tag? While Blazor is affected, I don't want this bug to get clumped in with existing known scaffolding issues in Blazor.

deepchoudhery commented 4 years ago

@HaoK that is the template that we have in the scaffolding repo. Is this intentional?

deepchoudhery commented 4 years ago

@javiercn should the account.manage layout be referencing the default/user defined layout or the aforementioned one?

iJoris commented 4 years ago

I can confirm that i get the same issue on the latest VS version.

Rick-Anderson commented 4 years ago

@HaoK @javiercn @deepchoudhery
It's not Blazor specific, All the templates use code very similar to https://github.com/dotnet/Scaffolding/blob/master/src/VS.Web.CG.Mvc/Templates/Identity/Bootstrap4/Pages/Account/Manage/Account.Manage._Layout.cshtml#L8

There is no such file as Layout = "/Areas/Identity/Pages/_Layout.cshtml";

I can't repo this being a problem because

if (ViewData.TryGetValue("ParentLayout", out var parentLayout))

always returns true. At least I can't figure out how to get it to return false. We have 0ver 30 customers reporting it is a problem in in https://github.com/dotnet/AspNetCore.Docs/issues/8440

image

The code is incorrect, it should be

"/Pages/Shared/_Layout.cshtml";

For Razor Pages, and the views folder for MVC.

This is trivial to repo with any of the web templates. For example:

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 

See this comment in a duplicate issue.

I could probably PR this if you like.

HaoK commented 4 years ago

Yeah its not supposed to match exactly, the UI does some magic to map the area path /Identity to the actual file

Rick-Anderson commented 4 years ago

I'll document that.

This issue and duplicate #931 should be closed.

In the Scaffold Identity doc I'll write something like Layout = "/Areas/Identity/Pages/_Layout.cshtml"; is correct because the user interface maps /Identity to the actual file

javiercn commented 4 years ago

The code is correct, we try to find the layout on the Area if there is no layout on the app, but use the layout on the app if present. SPA templates for example don't have a layout on the app and everything is self-contained within the Identity area. Blazor is a similar deal.

AndrewTriesToCode commented 2 years ago

FYI for anyone following along this issue seems to be resolved now. I noticed in August a file was added which explicity sets the parent view so that the bad path is not used. /Areas/Identity/Pages/Account/Manage/_ViewStart.cshtml

What's interesting is that this file doesn't get scaffolded so I spent a little while scratching my head on where ParentLayout was set until I checked the source on GitHub.