-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Blazor project template (#52234)
# Use consistent code style in Blazor project templates - Removed usage of top-level statements in client project if "Do not use top-level statements" is selected - Removed extra "@" in `@render-mode` values - Always use `typeof(Namespace._Imports).Assembly` instead of `typeof(Counter).Assembly` so the compilation does not break when the sample Counter component is removed, and so the code is more consistent with how it is when no sample content is generated - Added Account/AccessDenied endpoint to individual auth option to match Identity UI razor pages. This is shown when the user is authenticated but unauthorized by default. Fixes #52079 Fixes #52084 Fixes #52167 ## Customer Impact In addition to not using top-level statements when the customer requests that we don't, this improves code style consistency within the Blazor project template and with the Blazor docs. ## Regression? - [ ] Yes - [x] No ## Risk - [ ] High - [ ] Medium - [x] Low These are small stylistic changes to the Blazor project templates. ## Verification - [x] Manual (required) - [ ] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [x] N/A
- Loading branch information
Showing
8 changed files
with
59 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...tes/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp.Client/Program.Main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#if (IndividualLocalAuth) | ||
using BlazorWeb_CSharp.Client; | ||
using Microsoft.AspNetCore.Components.Authorization; | ||
#endif | ||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
|
||
namespace BlazorWeb_CSharp.Client; | ||
|
||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
|
||
#if (IndividualLocalAuth) | ||
builder.Services.AddAuthorizationCore(); | ||
builder.Services.AddCascadingAuthenticationState(); | ||
builder.Services.AddSingleton<AuthenticationStateProvider, PersistentAuthenticationStateProvider>(); | ||
|
||
#endif | ||
await builder.Build().RunAsync(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...tes/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/Pages/AccessDenied.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@page "/Account/AccessDenied" | ||
|
||
<PageTitle>Access denied</PageTitle> | ||
|
||
<header> | ||
<h1 class="text-danger">Access denied</h1> | ||
<p class="text-danger">You do not have access to this resource.</p> | ||
</header> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters