From e011406e89fa49d7c468a47db874b613a3dc804f Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Mon, 25 Sep 2023 15:50:34 +0100 Subject: [PATCH 01/23] Begin making it work --- .../.template.config/template.json | 19 +++++++++--- .../BlazorWeb-CSharp/Components/App.razor | 25 +++++++++++++-- .../Components/Identity/AccountLayout.razor | 27 ++++++++++++++++ .../{Layout => Identity}/ManageLayout.razor | 2 +- .../{Layout => Identity}/ManageNavMenu.razor | 0 .../Components/Layout/NavMenu.razor | 7 +---- .../Pages/Account/Manage/_Imports.razor | 2 +- .../Components/Pages/Account/_Imports.razor | 1 + .../Identity/PageLayoutTypeExtensions.cs | 31 +++++++++++++++++++ 9 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Identity/AccountLayout.razor rename src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/{Layout => Identity}/ManageLayout.razor (93%) rename src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/{Layout => Identity}/ManageNavMenu.razor (100%) create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Identity/PageLayoutTypeExtensions.cs diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.json b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.json index 9356b1e5a7a1..eab31b974bf5 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.json +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.json @@ -67,7 +67,12 @@ "condition": "(UseWebAssembly && InteractiveAtRoot)", "rename": { "BlazorWeb-CSharp/Components/Layout/": "./BlazorWeb-CSharp.Client/Layout/", - "BlazorWeb-CSharp/Components/Pages/": "./BlazorWeb-CSharp.Client/Pages/", + "BlazorWeb-CSharp/Components/Pages/Home.razor": "./BlazorWeb-CSharp.Client/Pages/Home.razor", + "BlazorWeb-CSharp/Components/Pages/Home.razor.css": "./BlazorWeb-CSharp.Client/Pages/Home.razor.css", + "BlazorWeb-CSharp/Components/Pages/Weather.razor": "./BlazorWeb-CSharp.Client/Pages/Weather.razor", + "BlazorWeb-CSharp/Components/Pages/Weather.razor.css": "./BlazorWeb-CSharp.Client/Pages/Weather.razor.css", + "BlazorWeb-CSharp/Components/Pages/Counter.razor": "./BlazorWeb-CSharp.Client/Pages/Counter.razor", + "BlazorWeb-CSharp/Components/Pages/Counter.razor.css": "./BlazorWeb-CSharp.Client/Pages/Counter.razor.css", "BlazorWeb-CSharp/Components/Routes.razor": "./BlazorWeb-CSharp.Client/Routes.razor" } }, @@ -114,8 +119,6 @@ "condition": "(!IndividualLocalAuth)", "exclude": [ "BlazorWeb-CSharp/Components/Identity/**", - "BlazorWeb-CSharp/Components/Layout/ManageLayout.razor", - "BlazorWeb-CSharp/Components/Layout/ManageNavMenu.razor", "BlazorWeb-CSharp/Components/Pages/Account/**", "BlazorWeb-CSharp/Data/**", "BlazorWeb-CSharp/Identity/**", @@ -189,6 +192,12 @@ "exclude": [ "BlazorWeb-CSharp/Data/SqlServer/**" ] + }, + { + "condition": "(IndividualLocalAuth && !InteractiveAtRoot)", + "exclude": [ + "BlazorWeb-CSharp/Identity/PageLayoutTypeExtensions.cs" + ] } ] } @@ -349,7 +358,7 @@ "defaultValue": "InteractivePerPage", "displayName": "_Interactivity location", "description": "Chooses which components will have interactive rendering enabled", - "isEnabled": "(InteractivityPlatform != \"None\" && auth == \"None\")", + "isEnabled": "(InteractivityPlatform != \"None\")", "choices": [ { "choice": "InteractivePerPage", @@ -413,7 +422,7 @@ "AllInteractive": { "type": "parameter", "datatype": "bool", - "isEnabled": "(InteractivityPlatform != \"None\" && auth == \"None\")", + "isEnabled": "(InteractivityPlatform != \"None\")", "defaultValue": "false", "displayName": "_Enable interactive rendering globally throughout the site", "description": "Configures whether to make every page interactive by applying an interactive render mode at the top level. If false, pages will use static server rendering by default, and can be marked interactive on a per-page or per-component basis." diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/App.razor b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/App.razor index 6559a81a3231..3f66b9393436 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/App.razor +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/App.razor @@ -1,4 +1,8 @@ - +@*#if (IndividualLocalAuth) +@using BlazorWeb_CSharp.Components.Identity + +##endif*@ + @@ -15,6 +19,8 @@ ##endif*@ @*#if (!InteractiveAtRoot) + ##elseif (IndividualLocalAuth) + ##elseif (UseServer && UseWebAssembly) ##elseif (UseServer) @@ -27,14 +33,29 @@ @*#if (!InteractiveAtRoot) - ##elseif (UseServer && UseWebAssembly) --> + ##elseif (IndividualLocalAuth) + + ##elseif (UseServer && UseWebAssembly) ##elseif (UseServer) ##else ##endif*@ + @*#if (IndividualLocalAuth) + + ##endif*@ +@*#if (InteractiveAtRoot && IndividualLocalAuth) + +@code { + [CascadingParameter] HttpContext? HttpContext { get; set; } + + IComponentRenderMode? RenderModeForPage => HttpContext.PageHasLayout() + ? null + : RenderMode.InteractiveServer; +} +##endif*@ diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Identity/AccountLayout.razor b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Identity/AccountLayout.razor new file mode 100644 index 000000000000..fa4c1f80b92c --- /dev/null +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Identity/AccountLayout.razor @@ -0,0 +1,27 @@ +@inherits LayoutComponentBase +@layout BlazorWeb_CSharp.Components.Layout.MainLayout +@inject NavigationManager Nav + +@if (HttpContext is null) +{ +

Loading...

+} +else +{ + @Body +} + +@code { + [CascadingParameter] HttpContext? HttpContext { get; set; } + + protected override void OnParametersSet() + { + if (HttpContext is null) + { + // If this code runs, we're currently rendering in interactive mode, so there is no HttpContext. + // The identity pages need to set cookies, so they require an HttpContext. To achieve this we + // must transition back from interactive mode to a server-rendered page. + Nav.Refresh(forceReload: true); + } + } +} diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/ManageLayout.razor b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Identity/ManageLayout.razor similarity index 93% rename from src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/ManageLayout.razor rename to src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Identity/ManageLayout.razor index e4a7871bbc75..949bc92215cb 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/ManageLayout.razor +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Identity/ManageLayout.razor @@ -1,5 +1,5 @@ @inherits LayoutComponentBase -@layout MainLayout +@layout AccountLayout

Manage your account

diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/ManageNavMenu.razor b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Identity/ManageNavMenu.razor similarity index 100% rename from src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/ManageNavMenu.razor rename to src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Identity/ManageNavMenu.razor diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/NavMenu.razor b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/NavMenu.razor index 5b38b21d63a7..1cea17303955 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/NavMenu.razor +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/NavMenu.razor @@ -1,8 +1,4 @@ -@*#if (IndividualLocalAuth) -@using BlazorWeb_CSharp.Components.Identity - -##endif*@ -