Authentication
Use ShellUI in apps with ASP.NET Core Identity, and style the sign-in pages with the auth blocks
New in 0.4: ShellUI supports Blazor apps created with ASP.NET Core Identity, and three blocks restyle the sign-in, sign-up and account recovery pages.
dotnet new blazor -n MyApp --auth Individual
cd MyApp
shellui init --dashboard 02
shellui add auth-01
What init does in an Identity app
The Identity pages under /Account set sign-in cookies, so they need a real HTTP request and must render statically. init makes the rest of the app interactive and keeps those pages static.
In 0.3, init made every page interactive, and the Identity pages returned Not Found.
init leaves the Bootstrap markup of the Identity pages alone. The auth blocks below restyle them.
The dashboard and the signed-in user
With a dashboard layout, the sidebar footer follows the sign-in state:
| State | Sidebar footer |
|---|---|
| Signed out | Log in and Register links |
| Signed in | The user's name, linking to the account page, and Log out |
The CLI adds this when it sets up the dashboard in an Identity app. A footer you have edited is left alone.
Auth blocks
| Block | Design | Install |
|---|---|---|
auth-01 |
Centered card on a muted background | shellui add auth-01 |
auth-02 |
Split screen: the form beside a brand panel | shellui add auth-02 |
auth-03 |
Minimal centered form | shellui add auth-03 |
See all three live on the Blocks page.
Adding one:
- Installs
AuthLayout0x.razorand sets it as the layout inComponents/Account/Pages/_Imports.razor, so the sign-in pages render without the dashboard sidebar. - Restyles the Identity pages with ShellUI's button, input and alert styles, when they are unchanged from
dotnet new blazorfor .NET 8, 9 or 10. Pages you have edited are kept and listed. - Leaves the account management pages under
Account/Manageon the app's layout.
Add a different auth block to switch designs.
Branding
The layouts show a placeholder logo and "My App". Edit the installed AuthLayout0x.razor to use your own.
Protecting pages
ShellUI doesn't change how authorization works. Use Blazor's own attributes and components:
@page "/reports"
@attribute [Authorize]
<AuthorizeView>
<Authorized>Signed in as @context.User.Identity?.Name</Authorized>
<NotAuthorized>Please log in.</NotAuthorized>
</AuthorizeView>