From 5a1f1a8ccb9e415f644bb4d86450d3427e075d7d Mon Sep 17 00:00:00 2001 From: "soroush.asadi" Date: Fri, 19 Jun 2026 09:01:45 +0330 Subject: [PATCH] fix(seo): proper 500 handler + safe JSON-LD escaping Add UseExceptionHandler(/error) so unhandled exceptions return a proper HTML 500 instead of a raw response Googlebot was logging as a server error in Search Console. Replace manual quote-only escaping in blog JSON-LD with a J() helper that uses JsonSerializer so newlines, backslashes, and all other control characters are safely escaped. Co-Authored-By: Claude Sonnet 4.6 --- DrSousan.Api/Pages/Blog/Post.cshtml | 12 +++++++----- DrSousan.Api/Program.cs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/DrSousan.Api/Pages/Blog/Post.cshtml b/DrSousan.Api/Pages/Blog/Post.cshtml index d25d814..e0eb02d 100644 --- a/DrSousan.Api/Pages/Blog/Post.cshtml +++ b/DrSousan.Api/Pages/Blog/Post.cshtml @@ -8,6 +8,8 @@ var articleType = ViewData["ArticleType"]?.ToString() ?? "MedicalWebPage"; var pubDate = post.PublishedAt?.ToString("yyyy-MM-ddTHH:mm:ssZ") ?? ""; var updDate = post.UpdatedAt.ToString("yyyy-MM-ddTHH:mm:ssZ"); + // Escape a string for safe embedding inside a JSON string literal. + static string J(string? s) => System.Text.Json.JsonSerializer.Serialize(s ?? "")[1..^1]; } @section Head { @@ -32,13 +34,13 @@