Skip to content

Commit

Permalink
Migrate to asp.net 8.0 (#32)
Browse files Browse the repository at this point in the history
* Migrate project to asp.net 8.0
* Bootstrap 5 modifications
* Gulpfile: Add bootstrap.bundle.min.js
* _Layout.cshtml: Change to local bootstrap assets (css + js)
* Remove unnecessary jquery references
* Remove unused ValidationScriptsPartial.cshtml
* Migrate app_offline.htm from bootstrap v4 to v5
* Github workflow: Update for dotnet 8, replace depreciated actions
  • Loading branch information
axunonb authored Mar 21, 2024
1 parent 879d082 commit e08d893
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 163 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build + test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions ClubSite/Areas/Manager/Pages/Login.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
(function () {
'use strict';
window.addEventListener('load', function () {
var forms = document.getElementsByClassName('needs-validation');
var validation = Array.prototype.filter.call(forms, function (form) {
const forms = document.getElementsByClassName('needs-validation');
const validation = Array.prototype.filter.call(forms, function (form) {
form.addEventListener('submit', function (event) {
if (form.checkValidity() === false) {
event.preventDefault();
Expand Down
136 changes: 63 additions & 73 deletions ClubSite/ClubSite.csproj
Original file line number Diff line number Diff line change
@@ -1,75 +1,65 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>3.6.0</Version>
<Authors>axuno gGmbH</Authors>
<Description>The source code for https://www.volleyballclub.de/</Description>
<CurrentYear>$([System.DateTime]::Now.ToString(yyyy))</CurrentYear>
<Copyright>Copyright 2020-$(CurrentYear) axuno gGmbH and Contributors</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<!-- With dotnet, add parameter: -p:SatelliteResourceLanguages="""en;de""" -->
<SatelliteResourceLanguages>en;de</SatelliteResourceLanguages>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="EPPlus" Version="7.0.5" />
<PackageReference Include="MailKit" Version="4.3.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.16" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.8" />
<PackageReference Include="Piranha" Version="10.4.0" />
<PackageReference Include="Piranha.AspNetCore" Version="10.4.0" />
<PackageReference Include="Piranha.AspNetCore.Identity" Version="10.4.0" />
<PackageReference Include="Piranha.AspNetCore.Identity.SQLServer" Version="10.4.0" />
<PackageReference Include="Piranha.AspNetCore.SimpleSecurity" Version="10.4.0" />
<PackageReference Include="Piranha.AttributeBuilder" Version="10.4.0" />
<PackageReference Include="Piranha.Data.EF.SQLServer" Version="10.4.0" />
<PackageReference Include="Piranha.ImageSharp" Version="10.4.0" />
<PackageReference Include="Piranha.Local.FileStorage" Version="10.4.0" />
<PackageReference Include="Piranha.Manager" Version="10.4.0" />
<PackageReference Include="Piranha.Manager.TinyMCE" Version="10.4.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\StatusCodes.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>StatusCodes.resx</DependentUpon>
</Compile>
<Compile Update="Resources\StatusDescriptions.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>StatusDescriptions.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\StatusCodes.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>StatusCodes.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\StatusDescriptions.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>StatusDescriptions.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<None Update="app_offline_.htm">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>4.0.0</Version>
<Authors>axuno gGmbH</Authors>
<Description>The source code for https://www.volleyballclub.de/</Description>
<CurrentYear>$([System.DateTime]::Now.ToString(yyyy))</CurrentYear>
<Copyright>Copyright 2020-$(CurrentYear) axuno gGmbH and Contributors</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<!-- With dotnet, add parameter: -p:SatelliteResourceLanguages="""en;de""" -->
<SatelliteResourceLanguages>en;de</SatelliteResourceLanguages>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="EPPlus" Version="7.0.10" />
<PackageReference Include="MailKit" Version="4.4.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.8" />
<PackageReference Include="Piranha" Version="11.0.0" />
<PackageReference Include="Piranha.AspNetCore" Version="11.0.0" />
<PackageReference Include="Piranha.AspNetCore.Identity" Version="11.0.0" />
<PackageReference Include="Piranha.AspNetCore.Identity.SQLServer" Version="11.0.0" />
<PackageReference Include="Piranha.AspNetCore.SimpleSecurity" Version="10.4.0" />
<PackageReference Include="Piranha.AttributeBuilder" Version="11.0.0" />
<PackageReference Include="Piranha.Data.EF.SQLServer" Version="11.0.0" />
<PackageReference Include="Piranha.ImageSharp" Version="11.0.0" />
<PackageReference Include="Piranha.Local.FileStorage" Version="11.0.0" />
<PackageReference Include="Piranha.Manager" Version="11.0.0" />
<PackageReference Include="Piranha.Manager.TinyMCE" Version="11.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.7" />
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\StatusCodes.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>StatusCodes.resx</DependentUpon>
</Compile>
<Compile Update="Resources\StatusDescriptions.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>StatusDescriptions.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\StatusCodes.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>StatusCodes.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\StatusDescriptions.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>StatusDescriptions.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="app_offline_.htm">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
11 changes: 6 additions & 5 deletions ClubSite/Controllers/Captcha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ClubSite.Controllers;
[Route("captcha")]
public class Captcha : Controller
{
async public Task<IActionResult> Index()
public async Task<IActionResult> Index()
{
return await GetSvgContent();
}
Expand All @@ -32,13 +32,14 @@ private Task<ContentResult> GetSvgContent()

// Change the response headers to output an un-cached image.
HttpContext.Response.Clear();
HttpContext.Response.Headers.Add("Expires", DateTime.UtcNow.Date.AddDays(-1).ToString("R"));
HttpContext.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate");
HttpContext.Response.Headers.Add("Pragma", "no-cache");
// Don't use Headers.Add() here, as it will add multiple headers of the same type.
HttpContext.Response.Headers.Append("Expires", DateTime.UtcNow.Date.AddDays(-1).ToString("R"));
HttpContext.Response.Headers.Append("Cache-Control", "no-store, no-cache, must-revalidate");
HttpContext.Response.Headers.Append("Pragma", "no-cache");

HttpContext.Response.ContentType = "image/svg+xml";
return Task.FromResult(Content(ci.Image));
}

private string CaptchaSessionKeyName => Library.CaptchaSvgGenerator.CaptchaSessionKeyName;
private static string CaptchaSessionKeyName => Library.CaptchaSvgGenerator.CaptchaSessionKeyName;
}
2 changes: 1 addition & 1 deletion ClubSite/Pages/TournamentRegistration.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ Vielen Dank!
Volleyballclub Neusäß e.V.
Browser: {(Request.Headers.ContainsKey(HeaderNames.UserAgent) ? Request.Headers[HeaderNames.UserAgent].ToString() : "unbekannt")}
Browser: {(Request.Headers.TryGetValue(HeaderNames.UserAgent, out var value) ? value.ToString() : "unbekannt")}
IP-Adresse: {HttpContext.Connection.RemoteIpAddress}
";
}
Expand Down
4 changes: 1 addition & 3 deletions ClubSite/Pages/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
<partial name="_Footer.cshtml" />
</div>
@if (!Env.IsDevelopment()) { <partial name="_GoogleAnalytics.cshtml"/> }
@* SRI Hash Generator: https://www.srihash.org/ *@
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha384-Qg00WFl9r0Xr6rUqNLv1ffTSSKEFFCDCKVyHZ+sVt8KuvG99nWw5RNvbhuKgif9z" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="~/assets/js/bootstrap/bootstrap.bundle.min.js" asp-append-version="true"></script>
@await RenderSectionAsync("script", false)
</body>
</html>
Expand Down
18 changes: 0 additions & 18 deletions ClubSite/Pages/_ValidationScriptsPartial.cshtml

This file was deleted.

8 changes: 2 additions & 6 deletions ClubSite/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,10 @@ public static async Task Main(string[] args)
.LoadConfigurationFromFile(Path.Combine(builder.Environment.ContentRootPath, ConfigurationFolder,
$"NLog.{builder.Environment.EnvironmentName}.config"));

builder.WebHost.ConfigureServices(WebAppStartup.ConfigureServices);
WebAppStartup.ConfigureServices(builder.Environment, builder.Configuration, builder.Services);

var app = builder.Build();

builder.WebHost.ConfigureAppConfiguration((context, confBuilder) =>
{
WebAppStartup.Configure(app, app.Services.GetRequiredService<ILoggerFactory>());
});
WebAppStartup.Configure(app, app.Services.GetRequiredService<ILoggerFactory>());

await app.RunAsync();
}
Expand Down
19 changes: 9 additions & 10 deletions ClubSite/WebAppStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,25 @@
using Piranha.AttributeBuilder;
using Piranha.Manager.Editor;
using Piranha;
using Piranha.AspNetCore.Models;

namespace ClubSite;

/// <summary>
/// The demo startup class to setup and configure the league.
/// The startup class to set up and configure the ClubSite.
/// </summary>
public static class WebAppStartup
{
/// <summary>
/// The method gets called by <see cref="Program"/> at startup, BEFORE building the app is completed.
/// </summary>
public static void ConfigureServices(WebHostBuilderContext context, IServiceCollection services)
public static void ConfigureServices(IWebHostEnvironment context, IConfigurationManager configuration, IServiceCollection services)
{
// required for cookies and session cookies (will throw CryptographicException without)
services.AddDataProtection()
.SetApplicationName(context.HostingEnvironment.ApplicationName)
.SetApplicationName(context.ApplicationName)
.SetDefaultKeyLifetime(TimeSpan.FromDays(360))
.PersistKeysToFileSystem(
new DirectoryInfo(Path.Combine(context.HostingEnvironment.ContentRootPath, "DataProtectionKeys")))
new DirectoryInfo(Path.Combine(context.ContentRootPath, "DataProtectionKeys")))
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration() {
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
Expand All @@ -54,12 +53,12 @@ public static void ConfigureServices(WebHostBuilderContext context, IServiceColl

// Custom ClubSite db context
services.AddDbContext<Data.ClubDbContext>((sp, options) =>
options.UseSqlServer(context.Configuration.GetConnectionString("VolleyballClub")));
options.UseSqlServer(configuration.GetConnectionString("VolleyballClub")));

// Piranha service setup
services.AddPiranha(svcBuilder =>
{
svcBuilder.AddRazorRuntimeCompilation = context.HostingEnvironment.IsDevelopment();
svcBuilder.AddRazorRuntimeCompilation = context.IsDevelopment();

svcBuilder.UseCms();
svcBuilder.UseFileStorage(naming: Piranha.Local.FileStorageNaming.UniqueFolderNames);
Expand All @@ -68,9 +67,9 @@ public static void ConfigureServices(WebHostBuilderContext context, IServiceColl
svcBuilder.UseTinyMCE();
svcBuilder.UseMemoryCache();
svcBuilder.UseEF<SQLServerDb>(db =>
db.UseSqlServer(context.Configuration.GetConnectionString("VolleyballClub")));
db.UseSqlServer(configuration.GetConnectionString("VolleyballClub")));
svcBuilder.UseIdentityWithSeed<IdentitySQLServerDb>(db =>
db.UseSqlServer(context.Configuration.GetConnectionString("VolleyballClub")));
db.UseSqlServer(configuration.GetConnectionString("VolleyballClub")));
});

// MUST be before AddMvc!
Expand Down Expand Up @@ -102,7 +101,7 @@ public static void ConfigureServices(WebHostBuilderContext context, IServiceColl
});

services.Configure<ConfigurationPoco.MailSettings>(
context.Configuration.GetSection(nameof(ConfigurationPoco.MailSettings)) ??
configuration.GetSection(nameof(ConfigurationPoco.MailSettings)) ??
throw new InvalidOperationException(
$"Configuration section '{nameof(ConfigurationPoco.MailSettings)}' not found."));

Expand Down
Loading

0 comments on commit e08d893

Please sign in to comment.