housekeeping updates #7
5 changed files with 64 additions and 98 deletions
|
@ -1,43 +0,0 @@
|
|||
@page "/authentication/{action}"
|
||||
@using System.Security.Claims
|
||||
@layout SimpleLayout
|
||||
|
||||
@code{
|
||||
private const string Login = "login";
|
||||
private const string Logout = "logout";
|
||||
public ClaimsPrincipal? User { get; private set; }
|
||||
|
||||
[CascadingParameter]
|
||||
public required Task<AuthenticationState> AuthenticationState { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string? Action { get; set; }
|
||||
|
||||
[Inject]
|
||||
public required NavigationManager NavigationManager { get; set; }
|
||||
|
||||
private void SignOut()
|
||||
{
|
||||
NavigationManager.NavigateTo("MicrosoftIdentity/Account/SignOut", true);
|
||||
}
|
||||
|
||||
private void SignIn()
|
||||
{
|
||||
NavigationManager.NavigateTo("MicrosoftIdentity/Account/SignIn", true);
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var authenticationState = await AuthenticationState;
|
||||
User = authenticationState.User;
|
||||
if (Action == Logout)
|
||||
{
|
||||
SignOut();
|
||||
}
|
||||
else if (Action == Login)
|
||||
{
|
||||
SignIn();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -21,11 +21,6 @@
|
|||
Thanks for visiting!
|
||||
</p>
|
||||
|
||||
<p class="mt-4 text-base leading-7 text-slate-900">
|
||||
Click this button to throw an error:
|
||||
<button class="px-4 py-2 bg-brand text-white rounded-md" @onclick="ThrowError">Throw Error</button>
|
||||
</p>
|
||||
|
||||
<div class="flex">
|
||||
<div class="w-full sm:w-auto">
|
||||
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-3">
|
||||
|
|
|
@ -5,30 +5,14 @@
|
|||
|
||||
<PageTitle>Not Found</PageTitle>
|
||||
|
||||
<div class="fixed inset-y-0 right-0 left-[40rem] hidden lg:block xl:left-[50rem] z-0">
|
||||
<svg
|
||||
viewBox="0 0 1080 957"
|
||||
fill="none"
|
||||
aria-hidden="true"
|
||||
class="absolute inset-0 h-full w-full"
|
||||
preserveAspectRatio="xMinYMid slice">
|
||||
<path fill="#2e3440" d="M0 0h1080v957H0z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<h1 class="mt-4 text-4xl md:text-5xl lg:text-6xl font-semibold text-[2rem] leading-10 tracking-tighter">Not Found</h1>
|
||||
<p class="text-slate text-xl mt-4">
|
||||
No page was found at <code>@Path</code>.
|
||||
</p>
|
||||
|
||||
<div class="px-4 py-10 sm:py-28 sm:px-6 lg:px-8 xl:py-32 xl:px-28">
|
||||
<div class="mx-auto max-w-xl lg:mx-0">
|
||||
<h1 class="mt-4 text-4xl md:text-5xl lg:text-6xl font-semibold text-[2rem] leading-10 tracking-tighter">Not Found</h1>
|
||||
<p class="text-slate text-xl mt-4">
|
||||
No page was found at <code>@Path</code>.<br/>
|
||||
</p>
|
||||
|
||||
<p class="text-blue-600 text-xl mt-4">
|
||||
<a href="/" aria-label="Home" class="underline">Go to home page</a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-blue-600 text-xl mt-4">
|
||||
<a href="/" aria-label="Home" class="underline">Go to home page</a>
|
||||
</p>
|
||||
|
||||
@code {
|
||||
private string Path { get; set; }
|
||||
|
|
|
@ -1,24 +1,33 @@
|
|||
<CascadingAuthenticationState>
|
||||
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] {typeof(Client._Imports).Assembly}">
|
||||
<Found Context="routeData">
|
||||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(SimpleLayout)">
|
||||
<NotAuthorized>
|
||||
@if (context.User.Identity?.IsAuthenticated != true)
|
||||
{
|
||||
<RedirectToLogin/>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p role="alert">You are not authorized to access this resource.</p>
|
||||
}
|
||||
</NotAuthorized>
|
||||
</AuthorizeRouteView>
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>Not found</PageTitle>
|
||||
<LayoutView Layout="@typeof(SimpleLayout)">
|
||||
<p role="alert">Sorry, there's nothing at this address.</p>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
</CascadingAuthenticationState>
|
||||
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] {typeof(Client._Imports).Assembly, typeof(AsyncEventHandler).Assembly}">
|
||||
<Found Context="routeData">
|
||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(SimpleLayout)"/>
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>Not found</PageTitle>
|
||||
<LayoutView Layout="@typeof(SimpleLayout)">
|
||||
<div class="fixed inset-y-0 right-0 left-[40rem] hidden lg:block xl:left-[50rem] z-0">
|
||||
<svg
|
||||
viewBox="0 0 1080 957"
|
||||
fill="none"
|
||||
aria-hidden="true"
|
||||
class="absolute inset-0 h-full w-full"
|
||||
preserveAspectRatio="xMinYMid slice">
|
||||
<path fill="#2e3440" d="M0 0h1080v957H0z"/>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="px-4 py-10 sm:py-28 sm:px-6 lg:px-8 xl:py-32 xl:px-28">
|
||||
<div class="mx-auto max-w-xl lg:mx-0">
|
||||
<h1 class="mt-4 text-4xl md:text-5xl lg:text-6xl font-semibold text-[2rem] leading-10 tracking-tighter">Not Found</h1>
|
||||
<p class="text-slate text-xl mt-4">
|
||||
No page was found at this address. Please check the web address and try again.
|
||||
</p>
|
||||
<p class="text-blue-600 text-xl mt-4">
|
||||
<a href="/" aria-label="Home" class="underline">Go to home page</a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
|
@ -1,6 +1,7 @@
|
|||
using Azure.Identity;
|
||||
|
||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Identity.Web;
|
||||
using Microsoft.Identity.Web.UI;
|
||||
|
@ -31,6 +32,20 @@ builder.Services.AddRazorComponents()
|
|||
.AddInteractiveServerComponents()
|
||||
.AddInteractiveWebAssemblyComponents();
|
||||
|
||||
builder.Services.AddProblemDetails(
|
||||
options =>
|
||||
{
|
||||
options.CustomizeProblemDetails = ctx =>
|
||||
{
|
||||
ctx.ProblemDetails.Extensions.TryAdd("traceId", ctx.HttpContext.TraceIdentifier);
|
||||
if (ctx.HttpContext.RequestServices.GetRequiredService<IHostEnvironment>()
|
||||
.IsDevelopment())
|
||||
{
|
||||
ctx.ProblemDetails.Extensions.TryAdd("exception", ctx.Exception?.ToString());
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
if (builder.Environment.IsStaging() || builder.Environment.IsProduction())
|
||||
{
|
||||
builder.Configuration.AddAzureAppConfiguration(
|
||||
|
@ -92,21 +107,27 @@ app.UseHttpLogging();
|
|||
app.UseHttpsRedirection();
|
||||
app.UseBlazorFrameworkFiles();
|
||||
app.UseStaticFiles(new StaticFileOptions {ServeUnknownFileTypes = true});
|
||||
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseAntiforgery();
|
||||
app.MapRazorComponents<App>()
|
||||
.AddAdditionalAssemblies(typeof(Counter).Assembly)
|
||||
.AddAdditionalAssemblies(typeof(AsyncEventHandler).Assembly)
|
||||
.AddInteractiveServerRenderMode()
|
||||
.AddInteractiveWebAssemblyRenderMode();
|
||||
|
||||
app.MapControllers();
|
||||
app.UseExceptionHandler();
|
||||
app.MapFallback(
|
||||
ctx =>
|
||||
{
|
||||
ctx.Response.Redirect($"/NotFound?path={ctx.Request.Path}");
|
||||
ctx.Response.StatusCode = StatusCodes.Status404NotFound;
|
||||
var headers = ctx.Request.GetTypedHeaders();
|
||||
if (headers.Accept.Any(h => h.MatchesMediaType("text/html")))
|
||||
{
|
||||
ctx.Response.Redirect($"/NotFound?path={ctx.Request.Path}");
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue