Skip to content

Commit

Permalink
add ServerRender sample
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Mar 13, 2024
1 parent 8fa01cc commit 9efa8b3
Show file tree
Hide file tree
Showing 31 changed files with 741 additions and 33 deletions.
9 changes: 8 additions & 1 deletion Blazone.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazone.Authentication.Test
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{F5705DB7-D853-4E18-B5BA-29916029FF25}"
ProjectSection(SolutionItems) = preProject
samples\WebAssembly\Directory.Build.props = samples\WebAssembly\Directory.Build.props
samples\Directory.Build.props = samples\Directory.Build.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.WebAssembly.Client", "samples\WebAssembly\Sample.WebAssembly.Client\Sample.WebAssembly.Client.csproj", "{948ABC1F-590F-4726-9CE1-AF4BFF13B024}"
Expand All @@ -29,6 +29,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{E0186A5E
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.ServerRender.Web", "samples\ServerRender\Sample.ServerRender.Web\Sample.ServerRender.Web.csproj", "{60E9A391-5DBF-441B-8D2F-C8B34B4F5F99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -59,6 +61,10 @@ Global
{2D47D31E-DB0D-4AF9-8AB1-368E420D612B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D47D31E-DB0D-4AF9-8AB1-368E420D612B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D47D31E-DB0D-4AF9-8AB1-368E420D612B}.Release|Any CPU.Build.0 = Release|Any CPU
{60E9A391-5DBF-441B-8D2F-C8B34B4F5F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60E9A391-5DBF-441B-8D2F-C8B34B4F5F99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60E9A391-5DBF-441B-8D2F-C8B34B4F5F99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60E9A391-5DBF-441B-8D2F-C8B34B4F5F99}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -68,6 +74,7 @@ Global
{948ABC1F-590F-4726-9CE1-AF4BFF13B024} = {F5705DB7-D853-4E18-B5BA-29916029FF25}
{EC7E6A3F-05CA-4564-AF44-E3A2F5492BFF} = {F5705DB7-D853-4E18-B5BA-29916029FF25}
{2D47D31E-DB0D-4AF9-8AB1-368E420D612B} = {F5705DB7-D853-4E18-B5BA-29916029FF25}
{60E9A391-5DBF-441B-8D2F-C8B34B4F5F99} = {F5705DB7-D853-4E18-B5BA-29916029FF25}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {28EA995C-96F4-4FAF-87D5-2D1F3CE67833}
Expand Down
File renamed without changes.
35 changes: 35 additions & 0 deletions samples/ServerRender/Sample.ServerRender.Web/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!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="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha256-PI8n5gCcz9cQqQXm3PEtDuPG8qx9oFsFctPg0S5zb8g="
crossorigin="anonymous">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css"
integrity="sha256-9kPW/n5nn53j4WMRYAxe9c1rCY96Oogo/MKSVdKzPmI="
crossorigin="anonymous">

<link rel="stylesheet" href="Sample.ServerRender.Web.styles.css" />
<link rel="stylesheet" href="app.css" />

<HeadOutlet @rendermode="InteractiveServer" />
</head>

<body>
<Routes @rendermode="InteractiveServer" />

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha256-CDOy6cOibCWEdsRiZuaHf8dSGGJRYuBGC+mjoJimHGw="
crossorigin="anonymous"></script>

<script src="_framework/blazor.web.js"></script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@inherits LayoutComponentBase

<Navigation />

<main role="main">
@Body
</main>

<Footer />

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}

#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@page "/claims"

@using Microsoft.AspNetCore.Authorization

@attribute [Authorize]

<PageTitle>Authorization Claims</PageTitle>

<div class="container-xxl">
<AuthorizeView Context="user">
<Authorized>
<h1>You are authenticated</h1>

<table class="table">
<thead>
<tr>
<th>Type</th>
<th>Value</th>
</tr>
</thead>
<tbody>
@foreach (var claim in user.User.Claims)
{
<tr>
<td>@claim.Type</td>
<td>@claim.Value</td>
</tr>
}
</tbody>
</table>
</Authorized>
<NotAuthorized>
<h1>You are not authenticated</h1>
</NotAuthorized>
</AuthorizeView>
</div>

@code {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@page "/counter"

<PageTitle>Counter</PageTitle>

<div class="container-xxl">
<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
</div>

@code {
private int currentCount = 0;

private void IncrementCount()
{
currentCount++;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@page "/Error"
@using System.Diagnostics

<PageTitle>Error</PageTitle>

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }

private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@page "/"

<PageTitle>Home</PageTitle>

<div class="container-xxl">
<div class="bg-light p-5 rounded">
<h1>
Blazone
</h1>
<p class="lead">
Blazone is a simple authentication module for Blazor
</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@page "/weather"
@inject WeatherForecastService WeatherForecastService

<PageTitle>Weather</PageTitle>

<div class="container-xxl">
<h1>Weather</h1>

<p>This component demonstrates fetching data from the server.</p>

@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
</div>

@code {
private WeatherForecast[]? forecasts;

protected override void OnInitialized()
{
forecasts = WeatherForecastService.Get().ToArray();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)">
<Authorizing>
<Loading />
</Authorizing>
<NotAuthorized>
<SignIn />
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<NotFound />
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="container">
<div class="row">
<div class="col-lg-6 mx-auto py-5">
<div class="card border-danger">
<div class="card-header text-white bg-danger">
<i class="fas fa-exclamation-triangle"></i> Access Denied
</div>
<div class="card-body text-danger">
<p>
You do not have access to this resource.
</p>
</div>
</div>
</div>
</div>
</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@if (Condition)
{
if (Passed != null)
{
@Passed
}
else if (ChildContent != null)
{
@ChildContent
}
}
else if (Failed != null)
{
@Failed
}

@code {

[Parameter] public bool Condition { get; set; }

[Parameter] public RenderFragment? ChildContent { get; set; }

[Parameter] public RenderFragment? Passed { get; set; }

[Parameter] public RenderFragment? Failed { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<footer class="border-top footer text-muted d-print-none">
<div class="container-fluid">
<div class="row">
<div class="col-md text-center">
<a href="https://github.com/loresoft/Blazone/"
title="GitHub Soure Code">
<i class="fab fa-github"></i> Source Code
</a>
</div>
<div class="col-md-6 text-center">
Copyright © @DateTime.Now.Year LoreSoft. All Rights Reserved.
</div>
<div class="col-md text-center" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
<span title="@ThisAssembly.InformationalVersion">Version @ThisAssembly.FileVersion</span>
</div>
</div>
</div>
</footer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="d-flex justify-content-center mb-3">
<span class="spinner-border" style="width: 3rem; height: 3rem;" role="status"></span>
</div>
<h3 class="d-flex justify-content-center">
@Text
</h3>

@code {
[Parameter]
public string Text { get; set; } = "Loading ...";
}
Loading

0 comments on commit 9efa8b3

Please sign in to comment.