Skip to content

Generate canonical and og:url from request path#1130

Open
BenjaminMichaelis wants to merge 2 commits into
mainfrom
benjaminmichaelis/canonical-url-metadata
Open

Generate canonical and og:url from request path#1130
BenjaminMichaelis wants to merge 2 commits into
mainfrom
benjaminmichaelis/canonical-url-metadata

Conversation

@BenjaminMichaelis
Copy link
Copy Markdown
Member

Why

The site metadata was inconsistent: og:url in _Layout.cshtml was hardcoded to the homepage, which did not match the actual route being viewed.

What changed

  • Generate a request-specific absolute URL in _Layout.cshtml from the current path.
  • Use that URL for both and .
  • Include X-Forwarded-Host in forwarded header processing so host resolution is correct behind proxies.

Notes for reviewers

  • This keeps the existing chapter head injection behavior while providing consistent layout-level metadata across routes.
  • Query strings remain excluded because canonical/OG values are path-based.

Copilot AI review requested due to automatic review settings May 18, 2026 16:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Generates per-request canonical and og:url URLs in the shared layout instead of hardcoding the homepage, and enables X-Forwarded-Host so the host resolves correctly behind the reverse proxy.

Changes:

  • Compute canonicalUrl from Request.Scheme, Request.Host, PathBase, and Path in _Layout.cshtml.
  • Use canonicalUrl for both <meta property="og:url"> and a new <link rel="canonical">.
  • Add ForwardedHeaders.XForwardedHost to the forwarded headers configuration.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
EssentialCSharp.Web/Views/Shared/_Layout.cshtml Builds a request-specific canonical URL and uses it for og:url and a new canonical link tag.
EssentialCSharp.Web/Program.cs Adds XForwardedHost to the accepted forwarded headers so Request.Host reflects the original host behind the proxy.

@BenjaminMichaelis
Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in b18d7c0. The conflict in Program.cs was between the branch's inline ForwardedHeadersOptions configuration (which added XForwardedHost) and main's refactored AddTrustedForwardedHeaders extension method. I resolved this by using AddTrustedForwardedHeaders (from main) and adding XForwardedHost to that extension in IServiceCollectionExtensions.cs to preserve the canonical URL functionality. _Layout.cshtml merged cleanly with all canonical URL changes intact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants