-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
migrated BlazorServer to Blazor web app
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
<CascadingAuthenticationState> | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"> | ||
<NotAuthorized> | ||
@if (context.User.Identity?.IsAuthenticated != true) | ||
{ | ||
<RedirectToLogin /> | ||
} | ||
else | ||
{ | ||
<p role="alert">You are not authorized to access this resource.</p> | ||
} | ||
</NotAuthorized> | ||
</AuthorizeRouteView> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1"/> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> | ||
</CascadingAuthenticationState> | ||
@inject IHostEnvironment Env | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<base href="/" /> | ||
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" /> | ||
<link href="css/site.css" rel="stylesheet" /> | ||
<link href="BlazorServer.styles.css" rel="stylesheet" /> | ||
<HeadOutlet @rendermode="InteractiveServer" /> | ||
</head> | ||
<body> | ||
<Routes @rendermode="InteractiveServer" /> | ||
<div id="blazor-error-ui"> | ||
@if (Env.IsDevelopment()) | ||
{ | ||
<text> | ||
An unhandled exception has occurred. See browser dev tools for details. | ||
</text> | ||
} | ||
else | ||
{ | ||
<text> | ||
An error has occurred. This app may no longer respond until reloaded. | ||
</text> | ||
} | ||
<a href="" class="reload">Reload</a> | ||
<a class="dismiss">🗙</a> | ||
</div> | ||
|
||
<script src="_framework/blazor.web.js"></script> | ||
</body> | ||
</html> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
@page "/" | ||
@using System.Security.Claims | ||
@inject AuthenticationStateProvider AuthenticationStateProvider | ||
|
||
<PageTitle>Index</PageTitle> | ||
|
||
<h1>Hello, world!</h1> | ||
|
||
Welcome to your new app. | ||
@if (User != null && User.Identity.IsAuthenticated) | ||
Check warning on line 9 in samples/BlazorServer/Pages/Index.razor GitHub Actions / macOS-latest
Check warning on line 9 in samples/BlazorServer/Pages/Index.razor GitHub Actions / macOS-latest
Check warning on line 9 in samples/BlazorServer/Pages/Index.razor GitHub Actions / ubuntu-latest
Check warning on line 9 in samples/BlazorServer/Pages/Index.razor GitHub Actions / ubuntu-latest
Check warning on line 9 in samples/BlazorServer/Pages/Index.razor GitHub Actions / windows-latest
|
||
{ | ||
<p>Welcome, @User.Identity.Name!</p> | ||
} | ||
else | ||
{ | ||
<p>Welcome to our app!</p> | ||
<p>You are not authenticated.</p> | ||
<p>Please <NavLink href="/account/login">log in</NavLink> to continue.</p> | ||
} | ||
|
||
<SurveyPrompt Title="How is Blazor working for you?"/> | ||
<SurveyPrompt Title="How is Blazor working for you?"/> | ||
|
||
@code { | ||
private ClaimsPrincipal User { get; set; } | ||
Check warning on line 23 in samples/BlazorServer/Pages/Index.razor GitHub Actions / macOS-latest
Check warning on line 23 in samples/BlazorServer/Pages/Index.razor GitHub Actions / macOS-latest
Check warning on line 23 in samples/BlazorServer/Pages/Index.razor GitHub Actions / ubuntu-latest
Check warning on line 23 in samples/BlazorServer/Pages/Index.razor GitHub Actions / ubuntu-latest
Check warning on line 23 in samples/BlazorServer/Pages/Index.razor GitHub Actions / windows-latest
Check warning on line 23 in samples/BlazorServer/Pages/Index.razor GitHub Actions / windows-latest
|
||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); | ||
User = authState.User; | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<CascadingAuthenticationState> | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"> | ||
<NotAuthorized> | ||
@if (context.User.Identity?.IsAuthenticated != true) | ||
{ | ||
<RedirectToLogin /> | ||
} | ||
else | ||
{ | ||
<p role="alert">You are not authorized to access this resource.</p> | ||
} | ||
</NotAuthorized> | ||
</AuthorizeRouteView> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> | ||
</CascadingAuthenticationState> |