Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to dotnet 8 and Blazor Web Apps #16

Merged
merged 3 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
60 changes: 42 additions & 18 deletions App.razor
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="typeof(MainLayout)">
<NotAuthorized>
<RedirectToLogin/>
</NotAuthorized>
<Authorizing>
Authorizing...
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<PageTitle>Not found - PartyGameTime</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
@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 href="css/site.css" rel="stylesheet" />
<link href="PartyGameTime.styles.css" rel="stylesheet" />
<link rel="icon" type="image/png" href="favicon.png"/>
<HeadOutlet @rendermode="InteractiveServer" />

<!-- MudBlazor -->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
<!-- End MudBlazor -->
</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>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions Core/Auth/BlazorCookieLoginMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public async Task Invoke(HttpContext context, SignInManager<Account> signInMgr)
await signInMgr.SignOutAsync();
context.Response.Redirect("/");
}
else if (context.Request.Path == "/Account/Login") // Fix for dotnet 8
{
context.Response.Redirect("/auth/login");
}
else
{
await _next.Invoke(context);
Expand Down
39 changes: 0 additions & 39 deletions Pages/_Host.cshtml

This file was deleted.

20 changes: 10 additions & 10 deletions PartyGameTime.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MudBlazor" Version="6.11.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using PartyGameTime.Core.Auth;
using PartyGameTime.Core.Services.Notifications;
using PartyGameTime;


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
builder.Services.AddMudServices();
builder.Services.AddSingleton<GlobalValuesManager>();

Expand Down Expand Up @@ -110,7 +111,7 @@
app.UseMiddleware<BlazorCookieLoginMiddleware>();
// Authentication end

app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.UseAntiforgery();
app.Run();
18 changes: 18 additions & 0 deletions Routes.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="typeof(MainLayout)">
<NotAuthorized>
<RedirectToLogin/>
</NotAuthorized>
<Authorizing>
Authorizing...
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<PageTitle>Not found - PartyGameTime</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
4 changes: 3 additions & 1 deletion _Imports.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@using System.Net.Http
@using static Microsoft.AspNetCore.Components.Web.RenderMode

@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
Expand All @@ -9,8 +11,8 @@
@using PartyGameTime
@using PartyGameTime.Shared
@using MudBlazor
@using Microsoft.AspNetCore.Components.Authorization

Check warning on line 14 in _Imports.razor

View workflow job for this annotation

GitHub Actions / build

The using directive for 'Microsoft.AspNetCore.Components.Authorization' appeared previously in this namespace
@using Microsoft.AspNetCore.Authorization

Check warning on line 15 in _Imports.razor

View workflow job for this annotation

GitHub Actions / build

The using directive for 'Microsoft.AspNetCore.Authorization' appeared previously in this namespace
@using PartyGameTime.Core.Auth
@using PartyGameTime.Components
@using PartyGameTime.Components.Dialog
Expand Down
Loading