From dd87a693bd6bf9bd73e82b80f5238faa0a730257 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Mon, 18 May 2026 09:23:32 -0700 Subject: [PATCH] Generate canonical and og:url from request path --- EssentialCSharp.Web/Program.cs | 2 +- EssentialCSharp.Web/Views/Shared/_Layout.cshtml | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/EssentialCSharp.Web/Program.cs b/EssentialCSharp.Web/Program.cs index 78a8a061..ccbb293f 100644 --- a/EssentialCSharp.Web/Program.cs +++ b/EssentialCSharp.Web/Program.cs @@ -122,7 +122,7 @@ private static void Main(string[] args) builder.Services.Configure(options => { options.ForwardedHeaders = - ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; + ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost; // Only loopback proxies are allowed by default. // Clear that restriction because forwarders are enabled by explicit diff --git a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml index 3f19ac18..935c76e7 100644 --- a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml +++ b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml @@ -16,11 +16,17 @@ const string imageUrl = "https://essentialcsharp.com/images/icon.png"; const string description = "Accelerate your development knowledge with C# expert Mark Michaelis and Benjamin Michaelis' free, online comprehensive C# tutorial and reference that is updated through C# 11.0"; string title = $"Essential C#{(string.IsNullOrEmpty(ViewBag.PageTitle) ? string.Empty : $": {ViewBag.PageTitle}")}"; + string canonicalPath = $"{Context.Request.PathBase}{Context.Request.Path}"; + if (string.IsNullOrEmpty(canonicalPath)) + { + canonicalPath = "/"; + } + string canonicalUrl = $"{Context.Request.Scheme}://{Context.Request.Host}{canonicalPath}"; } - + @@ -87,6 +93,7 @@ + @await RenderSectionAsync("HeadAppend", required: false)